Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何继承PHAsset类并添加属性_Ios_Swift - Fatal编程技术网

Ios 如何继承PHAsset类并添加属性

Ios 如何继承PHAsset类并添加属性,ios,swift,Ios,Swift,AssetGridModel继承PHAsset类并添加isSelected属性 fileprivate var fetchResult: [AssetGridModel]! let allPhotosOptions = PHFetchOptions() allPhotosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)] let fetchAsse

AssetGridModel继承PHAsset类并添加isSelected属性

fileprivate var fetchResult: [AssetGridModel]!

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

为什么我出来的类型都是PHAsset,不是我写的继承类,也不能更改我添加的属性

请告诉我,谢谢你

使用运行时解决它

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
        }
    }
}
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
        }
    }
}