2015-05-19 32 views
0

我正在開發一個自定義的cordova插件。我需要調用iOS(Swift)的javascript方法和NSObject作爲參數。使用Swift iOS的Javascript核心框架將NSobject傳遞給javascript

let methodToBeCalled = context.objectForKeyedSubscript("videoStreamAvailableForRendering") 
    let valueReturnedFromMethod: JSValue = methodToBeCalled.callWithArguments([stream]) 
    println("valueReturnedFromMethod \(valueReturnedFromMethod.toObject())") 

stream」是我需要通過的對象。雖然經過串沒有錯誤,但是當我路過流對象,我得到以下錯誤:

NSForwarding: warning: object 0x100f6f5e0 of class 'SwiftObject' does not implement methodSignatureForSelector: -- trouble ahead Unrecognized selector +[SwiftObject copyWithZone:]

幫我出...

回答

0

我想原因是因爲stream需求是NSObject的子類或者它需要是一個自動橋接到Objective C對象的類的實例。

看看這篇文章的更多細節。 String可以工作,因爲String會自動橋接到NSString

When you bridge from a Swift array to an NSArray object, the elements in the Swift array must be AnyObject compatible. For example, a Swift array of type [Int] contains Int structure elements. The Int type is not an instance of a class, but because the Int type bridges to the NSNumber class, the Int type is AnyObject compatible. Therefore, you can bridge a Swift array of type [Int] to an NSArray object. If an element in a Swift array is not AnyObject compatible, a runtime error occurs when you bridge to an NSArray object.