Search code examples
swift3core-foundation

Core Foundation in swift 3


I use CF classes in swift 3, and want to properly manage them. For example I have this line:

let phones = ABRecordCopyValue(person, kABPersonPhoneProperty).takeRetainedValue()

Normally when I used address book classes back in objc, whenever I call method that has copy in name, and I need to call CFRelease() after I finish using that object.

Now in swift i have 4 options to call

takeRetainedValue()
takeUnretainedValue()
retain()
autorelease()

But there is no release(). So if i want to use CF object in swift and then release it, which of these do I use?


Solution

  • The call to takeRetainedValue() transfers ownership to ARC, consuming one retain. This takes care of your need to call release.