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
compiler verifies that the declaration can be used in objective C
objc attribute can be used to change the name of an Objective-C method or the name of a class
var enabled: Bool {
@objc(isEnabled) get { ... }
set { ... }
}
// You want to use MyDocument but keep compatibility with old archives
@objc(ABCMyDocument) class MyDocument : UIDocument {
// ...
}
CF Interoperability
CF in Objective-C
Lots of bridge casts
C arrays, NSArray, CFArrayRef
CGPointMake
CGColorSpaceRelease
CF in Swift
Managed CF Objects
let colorSpace = CGColorSpaceCreateDeviceRGB() // inferred as CGColorSpace
colorSpace is automatically released
let gradient = CGGradientCreateWithColors(colorSpace, [startColor, endCOlor], [0.0, 1.0])
let startPoint = CGPoint(x: width / 2, y: 0)
just made a C struct!
Explicitly Bridged APIs
Some CF APIs have not been audited for implicit bridging
Swift uses Unmanaged<T> when the ownership convention is unknown
Unmanaged<T> enables manual memory management
generic struct
let color = CGColorGetRandomColor().takeUnretainedValue() // inferred as CGColor
Audit CF APIs to ensure they conform to CF memory conventions
CF_IMPLICIT_BRIDGING_ENABLED
// your CF APIs
CF_IMPLICIT_BRIDGING_DISABLED