You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Swift 4 i am facing one compilation issue with below code .
var outCount:UInt32 = 0;
var rawProperties:UnsafeMutablePointer<objc_property_t?>! = class_copyPropertyList(clazz, &outCount)
Getting Compile time issue :Cannot convert value of type 'UnsafeMutablePointer<objc_property_t>?' (aka 'Optional<UnsafeMutablePointer<OpaquePointer>>') to specified type 'UnsafeMutablePointer<objc_property_t?>!' (aka 'ImplicitlyUnwrappedOptional<UnsafeMutablePointer<Optional<OpaquePointer>>>')
But when i am change it with ! to ? then able to compile but not getting class property count.
var rawProperties:UnsafeMutablePointer<objc_property_t?>? = class_copyPropertyList(clazz, &outCount)
Would any one can correct above code snippet?
Thanks
The text was updated successfully, but these errors were encountered:
The error message and the documentation https://developer.apple.com/documentation/objectivec/1418553-class_copypropertylist say that class_copyPropertyList returns a UnsafeMutablePointer<objc_property_t>?, but you have written UnsafeMutablePointer<objc_property_t?>?, with an extra ? inside the <...>. Could you say a bit more about what you mean by "not getting class property count"?
Also, attaching a complete xcode project or playground that demonstrates the full issue lets us help you better.
@huonw there is two things in attached screenshot if you seen.
In screen shot line number 348, when i am using only UnsafeMutablePointer<objc_property_t>? & i am not getting the length of returned array in outCount(it's zero in all case) of passes class instance.
In attached screenshot line number 349 is working with Swift 3 and i am getting length of array and it's working fine for me but after migrating whole project with Swift 4 & running it in Xcode9Beta6, i am getting compile time error mentioned in screenshot.
Can we have a call at your time so that i can share my screen and show you.
and for "not getting class property count" i mean length of array.
The problem is that the class_copyPropertyList is an Objective-C function, and so only understands Objective-C concepts. The properties of the MockupServer.Factory class are only Swift properties in your code, and need to be be marked with the @objc attribute for that function to know they exist. This can be done by placing @objc on each property (@objc var id: String = "") or by putting @objcMembers on the class itself (@objcMembers class Factory: NSObject) which is like marking everything in the class with @objc (properties and methods).
However, taking a step back, I'm not sure this is a good idea. This sort of reflection may be better handled in Swift with Mirrors, or some other approach that avoids being so dynamic.
(I'm closing as "invalid" because all the parts are behaving correctly here, but it is definitely confusing! It's one of the problems of having lots of Objective-C code around: some of it doesn't work as expected.)
Attachment: Download
Additional Detail from JIRA
md5: 6c7066a66ed3ffdcddaa192e8dc2def0
Issue Description:
In Swift 4 i am facing one compilation issue with below code .
var outCount:UInt32 = 0;
var rawProperties:UnsafeMutablePointer<objc_property_t?>! = class_copyPropertyList(clazz, &outCount)
Getting Compile time issue : Cannot convert value of type 'UnsafeMutablePointer<objc_property_t>?' (aka 'Optional<UnsafeMutablePointer<OpaquePointer>>') to specified type 'UnsafeMutablePointer<objc_property_t?>!' (aka 'ImplicitlyUnwrappedOptional<UnsafeMutablePointer<Optional<OpaquePointer>>>')
But when i am change it with ! to ? then able to compile but not getting class property count.
var rawProperties:UnsafeMutablePointer<objc_property_t?>? = class_copyPropertyList(clazz, &outCount)
Would any one can correct above code snippet?
Thanks
The text was updated successfully, but these errors were encountered: