V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
jecshcier
V2EX  ›  iOS

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

  •  
  •   jecshcier · 2018-01-09 15:21:58 +08:00 · 1498 次点击
    这是一个创建于 2545 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在用 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 应该怎么写?

    3 条回复    2018-01-09 16:06:52 +08:00
    mufeng
        1
    mufeng  
       2018-01-09 15:49:12 +08:00
    imagePickerVc?.didFinishPickingPhotosHandle = { (photos, assets, isSelectOriginalPhoto) -> Void in
    /// ba la ba la
    }
    jecshcier
        2
    jecshcier  
    OP
       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
        3
    jecshcier  
    OP
       2018-01-09 16:06:52 +08:00
    @mufeng 我是这么写的

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

    }
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2446 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 15:52 · PVG 23:52 · LAX 07:52 · JFK 10:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.