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

前端之家收集整理的这篇文章主要介绍了Swift 3 – PHFetchResult – 枚举对象 – 模糊使用’枚举对象’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
不太明白为什么我在“ Swift 3”中使用“枚举对象”模糊.
  1. let collections = PHAssetCollection.fetchAssetCollections(with: .moment,subtype: .any,options: nil)
  2.  
  3. collections.enumerateObjects { (collection,start,stop) in
  4. collection as! PHAssetCollection
  5. let assets = PHAsset.fetchAssets(in: collection,options: nil)
  6. assets.enumerateObjects({ (object,count,stop) in
  7. content.append(object)
  8. })
  9.  
  10. }

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

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

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

猜你在找的Swift相关文章