-
Notifications
You must be signed in to change notification settings - Fork 357
Open
Description
Hello,
To demonstrate my generic use, I write 2 pieces of code as below.
- This piece results in an error at the 'return' statement:
import Foundation
import Bond
protocol MyProtocolType { }
struct MyValueType: MyProtocolType { }
class MyCustomClass {
static let singleton = MyCustomClass()
private init() { }
func getList() -> ObservableArray<MyProtocolType> {
let list = MutableObservableArray([MyValueType()])
return list.readOnlyView
}
}
- This piece of code runs ok:
import Foundation
import Bond
protocol MyProtocolType { }
struct MyValueType: MyProtocolType { }
class MyCustomClass {
static let singleton = MyCustomClass()
private init() { }
func getList() -> ObservableArray<MyValueType> {
let list = MutableObservableArray([MyValueType()])
return list.readOnlyView
}
}
The difference is at the function's return type: ObservableArray<MyProtocolType> vs ObservableArray<MyValueType>.
I think the correct syntax for generic usage is the 1st one, but Xcode reports error with it. So I need to change to the 2nd one.
I don't understand it. Or is my syntax incorrect? If you know the reason, please point me out.
Thank you!
Metadata
Metadata
Assignees
Labels
No labels