bridgeToObjectiveC and makeObjectsPerformSelector in Swift beta 5

后端 未结 2 510
慢半拍i
慢半拍i 2020-12-17 04:18

I had this code with a completion handler working in Xcode 6 beta 4 that no longer works in Xcode 6 beta 5.

dropsToRemove.bridgeToObjectiveC().makeObjectsPer         


        
相关标签:
2条回答
  • 2020-12-17 05:01

    Someone from Apple has stated that those bridgeToObjectiveC and bridgeFromObjectiveC functions are meant as private functions, i.e. for Apple internal use only, and that they would go away.

    I will try to find the link to that statement in the developer forums, if you happen to be in the developer program.

    0 讨论(0)
  • 2020-12-17 05:19

    The bridgeToObjectiveC and bridgeFromObjectiveC functions are not available in Xcode 6.0 beta 5. Instead, cast to/from the appropriate Foundation type when you need to use that type's API on a Swift object. For example:

    var arr = ["One", "Two"]
    (arr as NSArray).indexOfObject("One")
    

    Apple has warned against (or explicitly made unavailable) using performSelector and related methods since the first Swift beta. Presumably any such API that were still available before beta 5 were unintentionally so.

    As the question you cited notes, you can use map to call a function/method on every element of an array. You can also use filter, find or a for-in loop, or after casting to NSArray, one of the enumerateObjects methods. Note that many consider it bad style to use the functional-programming constructs (map, filter, reduce, find) for tasks that aren't "functional" -- that is, to run code that has side effects. So a for-in loop might be the cleanest way to do what you're after.

    0 讨论(0)
提交回复
热议问题