mercredi 8 février 2017

Collection extension not visible when called within same extension?

Vote count: 0

I am using the following extension on Collection:

extension Collection where Indices.Iterator.Element == Index {

    subscript (safe index: Index) -> Generator.Element? {
        return indices.contains(index) ? self[index] : nil
    }

}

I want to then use it in a function found in another Collection extension like this:

extension Collection {

    func tesFunc() -> String? {

        let s = [safe:1]

        return nil
    }
}

I am not able to make this work. The error I get is: "Use of unresolved identifier 'safe'

How can use the save subscript in the function found on the second extension on Collection?

Error as shown in a Playground

asked 18 secs ago

Let's block ads! (Why?)



Collection extension not visible when called within same extension?

Aucun commentaire:

Enregistrer un commentaire