objective c - Swift equivalent of @encode -
is there swift equivalent objective-c's @encode
?
for instance
@encode(void *) // -> @"^v"
searching yielded nothing.
no, there isn't - because under hood swift classes don't use objective-c introspection work. there's no need calculate (like there in objective-c) in order pass/call data.
however, if need use dynamically @ runtime (say, interoperation existing objective-c methods) can either create objective-c call , pass object through or (for simple types) write lookup table.
the type encodings listed @ https://developer.apple.com/library/mac/documentation/cocoa/conceptual/objcruntimeguide/articles/ocrttypeencodings.html have map, , it's possible write switch type statement lookup.
but fundamentally if have type want pass in , find it's objective c encoding type, can use nsobject's objctype method:
var = 1 nsnumber string.fromcstring(i.objctype)! == "q"
if need pass through unmolested c string anyway, may not need convert swift string type.
Comments
Post a Comment