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

Swift protocol #159

Open
onmyway133 opened this issue May 29, 2016 · 3 comments
Open

Swift protocol #159

onmyway133 opened this issue May 29, 2016 · 3 comments

Comments

@onmyway133
Copy link
Owner

onmyway133 commented May 29, 2016

Extending generic struct with inheritance protocol. WORK 🎉 . But autocompletes shows all methods 😢

Type of expression is ambiguous without more context

protocol A {

}

protocol B: A {

}

protocol C: B {

}

struct Stack<T> {

}

extension UIView: B {

}

extension Stack where T: A {
    func a() {
        print("f")
    }
}

extension Stack where T: B {
    func b() {
        a()
    }
}

extension Stack where T: C {
    func c() {
        print("e")
    }
}
@onmyway133
Copy link
Owner Author

onmyway133 commented May 29, 2016

Protocol associatedtype with array. WORKS for f, not for g 😠

Cannot convert value of type '[Self.Action]' to expected argument type '[Actionable]'

protocol Actionable {

}

protocol M: class {
    associatedtype Action: Actionable
    var views: [Action] { get set }
}

func f(view: Actionable) {

}

func g(views: [Actionable]) {

}

extension M {
    func add(view: Action) {
        views.append(view)
        f(view)
        g(views)
    }
}

Oops, it is the same error for generic struct, too 😢

protocol Actionable {

}

struct M<T: Actionable> {
  var views: [T]
}

func g(views: [Actionable]) {

}

extension M {
  func add() {
    g(views)
  }
}

@onmyway133
Copy link
Owner Author

Use protocol as a generic constraint 🐼

Protocol 'ActionThatHaveCAAnimation' can only be used as a generic constraint because it has Self or associated type requirements

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