2017-05-26 23 views
0

AssetGridModel継承PHAssetクラスと私は、PHAssetクラスを継承して追加する方法属性

fileprivate var fetchResult: [AssetGridModel]! 

let allPhotosOptions = PHFetchOptions() 
     allPhotosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] 
     let fetchAssets = PHAsset.fetchAssets(with: allPhotosOptions) 

または私はタイプの出てきたのはなぜ

let fetchAssets = AssetGridModel.fetchAssets(with: allPhotosOptions) 

がPHAssetあるisSelectedプロパティではなく追加継承クラスを作成し、追加した属性を変更できません。

私に教えてください、

答えて

0

使用ランタイムが

extension PHAsset { 

    struct RuntimeKey { 
     static var isSelectedKey = UnsafeRawPointer.init(bitPattern: "isSelectedKey".hashValue) 
    } 

    var isSelectedImage: Bool? { 
     set { 
      objc_setAssociatedObject(self, PHAsset.RuntimeKey.isSelectedKey, newValue, .OBJC_ASSOCIATION_COPY_NONATOMIC) 
     } 
     get { 
      return objc_getAssociatedObject(self, PHAsset.RuntimeKey.isSelectedKey) as? Bool 
     } 
    } 
} 
それを解決ありがとう
関連する問題