微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swift 3 – PHFetchResult – 枚举对象 – 模糊使用’枚举对象’

不太明白为什么我在“ Swift 3”中使用“枚举对象”模糊.
let collections = PHAssetCollection.fetchAssetCollections(with: .moment,subtype: .any,options: nil)

    collections.enumerateObjects { (collection,start,stop) in
        collection as! PHAssetCollection
        let assets = PHAsset.fetchAssets(in: collection,options: nil)
        assets.enumerateObjects({ (object,count,stop) in
            content.append(object)
        })

    }

有什么想法吗?此代码在Swift 2.2中正常工作

我已经碰到了这几次,这似乎是Swift的尾随关闭语法的一个问题.包括闭包参数周围的括号应该做的诀窍:
collections.enumerateObjects({ (collection,stop) in
    collection as! PHAssetCollection
    let assets = PHAsset.fetchAssets(in: collection,options: nil)
    assets.enumerateObjects({ (object,stop) in
        content.append(object)
    })

})

编辑:请参阅rinTaro的答案,解释为什么会发生这种情况.

原文地址:https://www.jb51.cc/swift/319681.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐