I cannot explain why the compiler can't compile this minimal example.
For the line store.subscribe(self) I always get Ambiguous reference to member 'subscribe(_:transform:)
Did I miss something or is that a bug?
Version: 4.0.1
Swift: 4.0
I would appreciate any help. Thanks
struct AppState: StateType {
var studentState: StudentState
}
struct StudentState: StateType {
var students: [String: [Student]] = [:]
}
let store = Store<AppState>(
reducer: appReducer,
state: AppState(studentState: StudentState())
)
class StudentVC: UIViewController, StoreSubscriber {
override func viewWillAppear(_ animated: Bool) {
store.subscribe(self) { <--------- Ambiguous reference to member 'subscribe(_:transform:)
$0.select {
$0.studentState
}
}
}
func newState(state: StudentState) {
}
}
@krema The error is occuring because you're returning ($0.studentState.students) which is of type (StudentState) (note the () making it a tuple), but then you're referencing state: StudentState below.
You can resolve this by removing the parenthesis from the select return value.
I think the issue is that you can only subscribe to sub-states defined in AppState. Which in this case should be $0.studentState and not $0.studentState.students
Ah, yes, thats also causing an issue, since $0.studentState.students is [String: [Student]]
You could select that, but then you'd need func newState(state: [String: [Student]]) instead of state: StudentState
@mjarvis & @amreshkumar
Thanks for the quick response. I updated the code above with your suggestions
but still get the same problem.
Perhaps clean & build, or restart xcode/your computer? I just tested the following:
import ReSwift
struct Student {}
struct AppState: StateType {
var studentState: StudentState
}
struct StudentState: StateType {
var students: [String: [Student]] = [:]
}
func appReducer(_ action: Action, state: AppState?) -> AppState {
return state ?? AppState(studentState: StudentState())
}
let store = Store<AppState>(
reducer: appReducer,
state: AppState(studentState: StudentState())
)
class StudentVC: NSObject, StoreSubscriber {
func start() {
store.subscribe(self) {
$0.select {
$0.studentState
}
}
}
func newState(state: StudentState) {
}
}
And it compiles successfully.
Thank you for your help. I found the problem. :sweat_smile:
This line caused the issue:
typealias StoreSubscriberStateType = AppState
Didn't recognize it because I also had an additional newState function with AppState in it.
Wow, what a mess馃槃
Most helpful comment
Perhaps clean & build, or restart xcode/your computer? I just tested the following:
And it compiles successfully.