想问下这句 oc 代码的用 swift3 应该怎么调用?

2018-01-09 15:21:58 +08:00
 jecshcier

最近在用 oc 到 swift 的迁移,对 swift 实在生疏,oc 中的 TZImagePickController 中有这么一个属性

@property (nonatomic, copy) void (^didFinishPickingPhotosHandle)(NSArray<UIImage *> *photos,NSArray *assets,BOOL isSelectOriginalPhoto);

先前的调用方式是这样的

[imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { _fileArr = photos; NSString *webImg =[NSString stringWithFormat:@"[""]; for (int i=0; i<photos.count; i++) { // [self htmlForJPGImage:photos[i]] webImg =[webImg stringByAppendingString:[self htmlForJPGImage:photos[i]]]; webImg = [webImg stringByAppendingString:@"""]; if (i != photos.count - 1) { webImg = [webImg stringByAppendingString:@",""]; } else { webImg = [webImg stringByAppendingString:@"]"]; } } NSLog(@"%@",webImg); [self evaluateJsCode:callback val:webImg webview:self.webview]; }];

想问下改写成 swift3 应该怎么写?

1472 次点击
所在节点    iOS
3 条回复
mufeng
2018-01-09 15:49:12 +08:00
imagePickerVc?.didFinishPickingPhotosHandle = { (photos, assets, isSelectOriginalPhoto) -> Void in
/// ba la ba la
}
jecshcier
2018-01-09 16:06:02 +08:00
@mufeng 我试过这么写,结果报了以下错

Cannot assign value of type '([UIImage]!, [AnyObject]!, Bool) -> Void' to type '(([UIImage]?, [Any]?, Bool) -> Void)!'
jecshcier
2018-01-09 16:06:52 +08:00
@mufeng 我是这么写的

imagePickerVc?.didFinishPickingPhotosHandle = {(photos:[UIImage]!,assets:[AnyObject]!,isSelectOriginalPhoto:Bool) -> Void in

}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/421385

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX