core-foundation

Releasing Core Foundation object references

こ雲淡風輕ζ 提交于 2019-12-02 17:13:18
Do I need to release a Core Foundation objects to clear up memory? And if so, how? For example, in the code: ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef peopleArray = ABAddressBookCopyArrayOfAllPeople(addressBook); do I need to release peopleArray ? What about addressBook ? Yes, in CoreFoundation you have to release anything with Create or Copy in the name. You do this with CFRelease(). In your case, you should be releasing both the array and the address book references. The rules for memory management in Core Foundation are similar to those in Cocoa: if the method that

strong @property with __attribute__((NSObject)) for a CF type doesn't retain

匆匆过客 提交于 2019-12-02 15:55:16
UPDATE: This issue has been fixed as of Xcode 4.6! This technique now works as intended again. However, make sure to read the notes at the top of Rob Napier's excellent answer before you use it in your code. ORIGINAL POST (ARC, Xcode 4.3.1, iOS 5.1) I have a strong property of a CF type (CGImage) that I want to be automatically managed by ARC using __attribute__((NSObject)) (as in having retain & release in the synthesized setter, and it being nil'ed in dealloc), but it doesn't work: the object is not retained when I assign the property. A minimal example to reproduce: @interface TestClass :

CoreFoundation vs Foundation

允我心安 提交于 2019-12-02 15:52:07
In iPhone development, speed is of the essence. Does anyone know if there is a speed difference between using a CoreFoundation type (like CFMutableDictionaryRef) versus a Foundation type (its counterpart, NSMutableDictionary). I would think manipulating the CF type would be faster as it doesnt have to throw around ObjC runtime messages, is this an unfounded assumption, has anyone actually looked in to this? In a technical sense, yes, it is faster, for exactly that reason. In a practical sense, no, it's not faster. For one thing, the speed difference is tiny . We're talking milliseconds saved

CFRelease crash in iOS10

为君一笑 提交于 2019-12-02 10:41:00
Below is my code, which used to work fine till iOS 9. - (NSData *)encryptWithDataPublicKey:(NSString*)data keyTag:(NSString*)tag { SecKeyRef publicKey = NULL; NSData *publicTag = [NSData dataWithBytes:[tag UTF8String] length:[tag length]]; NSMutableDictionary *queryPublicKey = [[NSMutableDictionary alloc] init]; [queryPublicKey setObject:(__bridge id)kSecClassKey forKey:(__bridge id)kSecClass]; [queryPublicKey setObject:publicTag forKey:(__bridge id)kSecAttrApplicationTag]; [queryPublicKey setObject:(__bridge id)kSecAttrKeyTypeRSA forKey:(__bridge id)kSecAttrKeyType]; [queryPublicKey setObject

Swift: Extracting / downcasting CFType based CoreText types in a CFArray

筅森魡賤 提交于 2019-12-02 08:53:17
I am trying to port elements of the CoreAnimationText sample to Swift. I cannot figure out though, how to extract or downcast the elements of CTRun from an array, in order to pass them to functions that expect and act upon the Swift-ified CTRun type. I either get runtime errors or linking errors from the playground snippet below import CoreText import QuartzCore let text = NSAttributedString(string: "hello") var line: CTLine = CTLineCreateWithAttributedString(text) var ctRuns:CFArray = CTLineGetGlyphRuns(line) let nsRuns:Array<AnyObject> = ctRuns as NSArray nsRuns.count // == 1 // Playground

How to retrieve the values for the particular key from CFMutableDictionary

泄露秘密 提交于 2019-12-02 08:25:07
In C++ EventType.find(1)->second can be used to find the value for the key 1. I am new to Objective C.I have implemented CFDictionary to addvalue onto it.But how do i retreive and view the values of the particular key. EDITED: CFNumberRef tId = CFNumberCreate(NULL,kCFNumberShortType,&st); CFDictionarySetValue(cfdict,tId,st); NSLog(@"The value is:%s",(CFDictionaryGetValue(cfdict,tId))); Its running without error but i could not get the output. The documentation for CFMutableDictionary says: The basic interface for managing dictionaries is provided by CFDictionary Reference. ... which leads you

UnsafeMutablePointer<CFTypeRef> in Swift 3

淺唱寂寞╮ 提交于 2019-12-01 19:01:53
问题 I'm attempting to call SecItemCopyMatching in my keychain utility class in order to get data out of the keychain, yet I'm running into a problem with getting the result argument, UnsafeMutablePointer<CFTypeRef?> . The original statement (in Swift 2, before migrating to Swift 3) was // query is a dictionary of [String : AnyObject] var result: Data? let status = withUnsafeMutablePointer(to: &result) { SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0)) } But in Swift 3, you are

UnsafeMutablePointer<CFTypeRef> in Swift 3

与世无争的帅哥 提交于 2019-12-01 18:29:22
I'm attempting to call SecItemCopyMatching in my keychain utility class in order to get data out of the keychain, yet I'm running into a problem with getting the result argument, UnsafeMutablePointer<CFTypeRef?> . The original statement (in Swift 2, before migrating to Swift 3) was // query is a dictionary of [String : AnyObject] var result: Data? let status = withUnsafeMutablePointer(to: &result) { SecItemCopyMatching(query as CFDictionary, UnsafeMutablePointer($0)) } But in Swift 3, you are now required to call .withMemoryRebound in order to view memory. Based on what Xcode tells you to do,

Swift: CGPathRelease and ARC

柔情痞子 提交于 2019-12-01 16:18:57
Just updated to Xcode Beta 4, and noticed the following compiler error with my code below: var path = CGPathCreateMutable() ... CGPathRelease(path) 'CGPathRelease' is unavailable: Core Foundation objects are automatically memory managed So do I simply just remove my release calls and everything should be fine? Or is there something more I'm missing? And are there any special cases I should be aware of with ARC? The Working with Cocoa Data Types section of Using Swift with Cocoa and Objective-C says (emphasis mine): Core Foundation objects returned from annotated APIs are automatically memory

CFURLCreateDataAndPropertiesFromResource deprecated. And looking for substitute

别来无恙 提交于 2019-12-01 09:03:25
Along with a bunch of other things included in Apple's Load Preset Demo sample code, the call to CFURLCreateDataAndPropertiesFromResource is now deprecated. But I can't find a substitute for it - neither an option-click nor a look at the reference tell me any more than that it is no longer the done thing. CFDataRef propertyResourceData = 0; Boolean status; SInt32 errorCode = 0; OSStatus result = noErr; // Read from the URL and convert into a CFData chunk status = CFURLCreateDataAndPropertiesFromResource ( kCFAllocatorDefault, (__bridge CFURLRef) presetURL, &propertyResourceData, NULL, NULL,