Is there a way to reference instance function when calling SequenceType.forEach?

前端 未结 2 948
渐次进展
渐次进展 2020-12-19 16:52

Consider type Foo:

class Foo {

    var isBaz: Bool {
        return false
    }

    func bar() {
        print(\"some boring print\")
    }
}
         


        
2条回答
  •  轮回少年
    2020-12-19 17:45

    The $0 syntax is there to help you create a shortcut, but if you don't like it you can use the more complete form:

    someFoos.forEach { thisFoo in thisFoo.bar() }
    

提交回复
热议问题