Skip to content

Instantly share code, notes, and snippets.

@smic
Created August 23, 2018 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smic/01202aecd3ff0b3bf2035489ee4b66c1 to your computer and use it in GitHub Desktop.
Save smic/01202aecd3ff0b3bf2035489ee4b66c1 to your computer and use it in GitHub Desktop.
25: Cannot invoke initializer for type 'Holder<_>' with an argument list of type '(ObjectWithValue)'
class Holder<T: AnyObject> {
var value: T? = nil
init() {
self.value = nil
}
init(_ value: T) {
self.value = value
}
}
protocol ObjectWithValue: class {
var string: String { get }
}
class MyObject: ObjectWithValue {
var string: String = "test"
}
let object = MyObject()
let holder1 = Holder(object)
let objectByProtocol: ObjectWithValue = object
let holder2 = Holder(objectByProtocol)
let holder3 = Holder<ObjectWithValue>()
holder2.value = object
@smic
Copy link
Author

smic commented Aug 23, 2018

25: Cannot invoke initializer for type 'Holder<_>' with an argument list of type '(ObjectWithValue)'
27: 'Holder' requires that 'ObjectWithValue' be a class type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment