Swift and scriptingbridge object initialization

前端 未结 4 1942
天命终不由人
天命终不由人 2021-02-03 14:45

I\'m trying to write an application for swift control iTunes. But when initializing the application returns an object of type AnyObject, but must iTunesApplication.

4条回答
  •  清歌不尽
    2021-02-03 15:33

    An inelegant way to do work around the issue is to have iTunes declared as an SBApplication, then, when you call a function from iTunesApplication, downcast iTunes to an AnyObject:

    (iTunes as AnyObject).play()
    

    Note that there is no type-safety if you do this: you could call any function declared in any Objective-C header: it's just not guaranteed to be implemented in a specific class, and thus will crash the program.

提交回复
热议问题