New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic parameter 'Element' could not be inferred #53
Comments
The compiler may have output an incorrect error. BTW, thank you for opening some issues. |
Thanks for your quick answers. The reason I'm asking here is that it worked with RC2, I didn't expect any breaking changes in an RC. I'm trying to rewrite this part:
All CellNode's conform to Identifiable Component. I tried to rewrite it as Group(of: ) but wasn't able to. Maybe you can share the best way to go ahead? |
Dynamic type casting isn't compatible with function builder because Section(
id: "upcoming",
header: ViewNode(UpcomingHeader()),
cells: state.upcomingEvents.flatMap { event -> [CellNode] in
event.events.compactMap { eventType -> CellNode? in
//contact
if let contact = eventType as? Contact {
return CellNode(UpcomingContact(contact: contact))
}
//reminder
if let reminder = eventType as? (Reminder, Contact) {
return CellNode(UpcomingReminder(reminder: reminder))
}
//birthday
if let birthday = eventType as? (Date, Contact) {
return CellNode(UpcomingBirthday(birthday: birthday))
}
return nil
}
}
) |
Another approach with function builder. func component(for eventType: Any) -> AnyComponent? {
//contact
if let contact = eventType as? Contact {
return AnyComponent(UpcomingContactCellNode(contact: contact))
}
//reminder
if let reminder = eventType as? (Reminder, Contact) {
return AnyComponent(UpcomingReminderCellNode(reminder: reminder))
}
//birthday
if let birthday = eventType as? (Date, Contact) {
return AnyComponent(UpcomingBirthday(birthday: birthday))
}
return nil
}
Section(
id: "upcoming",
header:UpcomingHeader(),
cells: {
Group(of: state.upcomingEvents) { event in
Group(of: event.events.compactMap { eventType in
component(for: eventType)
}
}
}
) |
Thanks for your help. That approach works great. |
Checklist
Expected Behavior
While updating from RC2 to RC4, the next issue happens.
Current Behavior
Array of class [ClassName], using the group function to list as cells.
Detailed Description (Include Screenshots)
However, using another class results in this error:
Generic parameter 'Element' could not be inferred. Explicitly specify the generic arguments to fix this issue
When explicitly specifying arguments I get the following error:
Unable to infer closure type in the current context.
What am I doing wrong?
Environment
RC4
The text was updated successfully, but these errors were encountered: