JSExport不能使用多个参数的Objective-C方法吗?
考虑一下:
@protocol FooExport - (void)method1:(NSString *)param1; - (void)method2:(NSString *)param1 param2:(NSString *)param2; @end @interface Foo : NSObject @end @implementation Foo - (void)method1:(NSString *)param1 { NSLog(@"method1"); } - (void)method2:(NSString *)param1 param2:(NSString *)param2 { NSLog(@"method2"); } @end { sContext = [[JSContext alloc] init]; if (sContext) { sContext[@"foo"] = [[Foo alloc] init]; [sContext evaluateScript:@"foo.method1(\"foo\");"]; // method1 is called [sContext evaluateScript:@"foo.method2(\"foo\", \"bar\");"]; // method2 is NOT called } }
调用method1就好了但是从不调用method2。
如果我按如下方式更改method2:
@protocol FooExport - (void)method1:(NSString *)param1; - (void)method2:(NSString *)param1; @end
method2现在通过[sContext evaluateScript:@“foo.method2(\”foo \“,\”bar \“);”]; (我必须通过JSContext.currentArguments挖出第二个参数)。
同样,如果我按如下方式更改method2:
@protocol FooExport – (void)method1:(NSString *)param1; – (void)method2; @结束
method2再次通过[sContext evaluateScript:@“foo.method2(\”foo \“,\”bar \“);”]; (我必须通过JSContext.currentArguments挖出这两个参数)。
这是设计的吗? JSContext.currentArguments的缺点是我必须处理JSValues而不是已经转换的objective-C类型。
快速浏览JSContext.h揭示了这个gem:
// When a selector that takes one or more arguments is converted to a JavaScript // property name, by default a property name will be generated by performing the // following conversion: // - All colons are removed from the selector // - Any lowercase letter that had followed a colon will be capitalized. // Under the default conversion a selector "doFoo:withBar:" will be exported as // "doFooWithBar". The default conversion may be overriden using the JSExportAs // macro, for example to export a method "doFoo:withBar:" as "doFoo": // // @protocol MyClassJavaScriptMethods // JSExportAs(doFoo, // - (void)doFoo:(id)foo withBar:(id)bar // ); // @end // // Note that the JSExport macro may only be applied to a selector that takes one // or more argument. #define JSExportAs(PropertyName, Selector) \ @optional Selector __JS_EXPORT_AS__##PropertyName:(id)argument; @required Selector
- iPhone:如何使用NSUserDefaults存储UIImage?
- 为什么我要从越南搬到墨西哥
- 为什么添加对象后UIScrollView不能完全滚动? 使用故事板,ARC和Xcode 4.5.2
- Xcode 8 Swift 3:模态演示文稿转换委托不被调用
- 如何将今天的date和时间转换为GMTFormat(10位数字)
- NSFetchedResultsController的节名称与pipe理对象值不匹配
- 如何创build自定义MKAnnotationView和自定义注释标题和副标题
- 带有ORY Hydra,Vapor 3和iOS 12的OAuth2
- 错误ITMS-9000:“不支持的体系结构。 您的可执行文件包含不受支持的体系结构”“