Skip to content
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

Wrong generic use of ObservableArray/MutableObservableArray? #700

Open
vietstone-ng opened this issue Dec 27, 2020 · 0 comments
Open

Wrong generic use of ObservableArray/MutableObservableArray? #700

vietstone-ng opened this issue Dec 27, 2020 · 0 comments

Comments

@vietstone-ng
Copy link

Hello,

To demonstrate my generic use, I write 2 pieces of code as below.

  1. 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
  }
}
  1. 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant