0
我需要使用NSBlock作爲可以在JavaScript中進行更改的屬性。在JavaScriptCore中使用NSBlock作爲屬性
@protocol ExportingUser <NSObject, JSExport>
@property (nonatomic, copy) void (^changedName) (void);
@property (nonatomic) NSString* name;
@end
我基本上想從obj-C中調用changedName,它的定義來自JavaScript。就像這樣:
user.name = "Peyman"; // this will change the name property in the Obj-C as well.
user.changedName = function() { console.log("yay"); } // but this doesn't
我知道,這是有可能通過JSValue的callWithArguments方法,但如果可能的話,我更喜歡這種方法。
編輯:其實,我不認爲callWithArguments方法將工作。因爲綁定到Objective-C類的對象在JavaScript中不可擴展,所以引入新的字段可能會被忽略。