vendredi 26 avril 2019

Reflection error converting to Swift 4 in Objective-C properties

Getting error message

Cannot convert value of type 'UnsafeMutablePointer<objc_property_t>?' (aka 'Optional<UnsafeMutablePointer>') to specified type 'UnsafeMutablePointer<objc_property_t?>' (aka 'UnsafeMutablePointer<Optional<OpaquePointer>>')

On this line

let properties : UnsafeMutablePointer <objc_property_t?> = class_copyPropertyList(self.classForCoder, &count)

Full code here

var count = UInt32()
let properties : UnsafeMutablePointer <objc_property_t?> = class_copyPropertyList(self.classForCoder, &count)
var propertyNames = [String]()
let intCount = Int(count)
for i in 0..<intCount {
    let property : objc_property_t = properties[i]!
    guard let propertyName = NSString(utf8String: property_getName(property)) as? String else {
        debugPrint("Couldn't unwrap property name for \(property)")
        break
    }

    propertyNames.append(propertyName)
}





Aucun commentaire:

Enregistrer un commentaire