2017-05-26 4 views
0

AssetGridModel Inherit the PHAsset Klasse und fügen Sie die isSelected EigenschaftWie die PHAsset Klasse erben, und fügen Sie Attribute

fileprivate var fetchResult: [AssetGridModel]! 

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

oder

let fetchAssets = AssetGridModel.fetchAssets(with: allPhotosOptions) 

Warum ich aus dem Art gekommen sind PHAsset sind, nicht ich hat die Vererbungsklasse geschrieben und kann die hinzugefügten Attribute nicht ändern?

Bitte teilen Sie mir, danke

Antwort

0

Verwendung Runtime es

lösen
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 
     } 
    } 
} 
Verwandte Themen