Generate a UUID string with ARC enabled

Looks fine to me. This is what I use (available as a gist) – (NSString *)uuidString { // Returns a UUID CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault); NSString *uuidString = (__bridge_transfer NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid); CFRelease(uuid); return uuidString; } Edited to add If you are on OS X 10.8 or iOS 6 you can use the new NSUUID … Read more

How to debug memory leaks when Leaks instrument does not show them?

In Xcode 8, you can click on the “Debug Memory Graph” button, in the debug toolbar (shown at the bottom of the screen): See Apple’s Diagnosing and Resolving Bugs in Your Running App: Visualize and Diagnose Increasing Memory Usage. Just identify the object in the left panel that you think should have been deallocated, and … Read more

What is the equivalent of @autoreleasepool in Swift?

The syntax is as follows: autoreleasepool { /* code */ } Unfortunately Apple’s WWDC 2014 videos no-longer seem to be available. Incase it comes back, it was covered in WWDC 2014 session video number 418 “Improving Your App with Instruments”. The swift documentation doesn’t contain anything useful currently. But you can find plenty of good … Read more

@property definitions with ARC: strong or retain?

1) Shouldn’t retain now be replace with strong or weak? No. You cannot replace retain with weak; they are different. And strong is a 100% synonym for retain; they are identical. You can use either, so there is no “should” here. You can replace retain with strong if you like, but you don’t have to. … Read more

ARC – The meaning of __unsafe_unretained?

The LLVM Compiler 3.0 introduces four new ownership qualifiers: __strong, __autoreleasing, __unsafe_unretained, and __weak. The first three are available even outside ARC, as per the specification. As Joshua indicates, by default all pointers are implied to be __strong under ARC. This means that when an object is assigned to that pointer, it is retained for … Read more

ARC forbids Objective-C objects in structs or unions despite marking the file -fno-objc-arc

If you got this message try __unsafe_unretained. It is only safe, if the objects in the struct are unretained. Example: If you use OpenFeint with ARC the Class OFBragDelegateStrings says this error in a struct. typedef struct OFBragDelegateStrings { NSString* prepopulatedText; NSString* originalMessage; } OFBragDelegateStrings; to typedef struct OFBragDelegateStrings { __unsafe_unretained NSString* prepopulatedText; __unsafe_unretained NSString* … Read more

How do I replace weak references when using ARC and targeting iOS 4.0?

To target the older OS, you can use unsafe_unretained instead of weak in your property declaration, and it should mostly work the same way. weak references nil themselves when their target goes away, but unsafe_unretained leaves open the possibility that the object you’re linking to could turn into a dangling pointer when it is deallocated. … Read more