I just updated my project to Swift 2.
I one of my swift class I use ObjC association.
I have the following :
objc_AssociationPolicy( OBJC_ASSOCIATION_RETAIN_NONATOMIC)
Since the update, the compiler returns Use of unresolved identifier 'OBJC_ASSOCIATION_RETAIN_NONATOMIC'
.
Any idea why ?
答案:
If you look at the obj c runtime swift header, it appears this construct has become an enum:
/**
* Policies related to associative references.
* These are options to objc_setAssociatedObject()
*/enum objc_AssociationPolicy : UInt {
case OBJC_ASSOCIATION_ASSIGN case OBJC_ASSOCIATION_RETAIN_NONATOMIC case OBJC_ASSOCIATION_COPY_NONATOMIC case OBJC_ASSOCIATION_RETAIN case OBJC_ASSOCIATION_COPY}
So you can replace with: objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC
.
If you need the token as a UInt, you can always use .rawValue.
(In the previous version objc_AssociationPolicy
was just a typealias for UInt - with the effect of casting 'OBJC_ASSOCIATION_RETAIN_NONATOMIC', an Int)