automatic-ref-counting

Generate a UUID string with ARC enabled

早过忘川 提交于 2019-11-27 17:14:24
I need to generate a UUID string in some code with ARC enabled. After doing some research, this is what I came up with: CFUUIDRef uuid = CFUUIDCreate(NULL); NSString *uuidStr = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, uuid); CFRelease(uuid); Am I correctly using __bridge_transfer to avoid leaking any objects under ARC? 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);

Error compiling with ARC when runtime programming dynamic method

大憨熊 提交于 2019-11-27 16:59:14
问题 I am trying to do some runtime programmation on Objective-C. In order to do this I override the resolveClassMethod method. Unfortunately I come up with some compilation error with clang when ARC is active : error: no known class method for selector 'dynamic' Everything works fine if I use gcc or clang without ARC ( -fno-objc-arc option passed), except a warning instead of the error. I am aware that ARC need to know the name of the method called to figure out how to manage the memory with

weak or strong for IBOutlet and other [duplicate]

柔情痞子 提交于 2019-11-27 16:58:25
This question already has an answer here: Should IBOutlets be strong or weak under ARC? 11 answers I have switched my project to ARC, and I don't understand if I have to use strong or weak for IBOutlets. Xcode do this: in interface builder, if a create a UILabel for example and I connect it with assistant editor to my ViewController , it create this: @property (nonatomic, strong) UILabel *aLabel; It uses the strong , instead I read a tutorial on RayWenderlich website that say this: But for these two particular properties I have other plans. Instead of strong , we will declare them as weak .

How does my ARC app work in iOS 3.x?

China☆狼群 提交于 2019-11-27 16:49:17
问题 So I just found out that ARC is only supported for devices running iOS 4.0+. How does my app (in the store) work on devices running iOS 3.0 then (definitely using ARC)? I'm so confused. Solution from below: As long as I don't use zeroing weak references it seems that using ARC still works with iOS 3.x, but Apple just has not guaranteed the result. 回答1: ARC is mostly a compile time feature, the compiler inserts the appropiate release calls. AFAIK only zeroing weak references need runtime

Do I set properties to nil in dealloc when using ARC?

回眸只為那壹抹淺笑 提交于 2019-11-27 16:36:58
I am trying to learn Automatic Reference Counting in iOS 5. Now the first part of this question should be easy: Is it correct that I do NOT need to write explicit release-property statements in my dealloc when using ARC? In other words, is it true that the following does NOT need a explicit dealloc? @interface MyClass : NSObject @property (strong, nonatomic) NSObject* myProperty; @end @implementation MyClass @synthesize myProperty; @end My next and more important question comes from a line in the Transitioning to ARC Release Notes document: You do not have to (indeed cannot) release instance

ios: using the same sqlite parameter more than once causes premature memory deallocation

不问归期 提交于 2019-11-27 16:24:57
Note: the question is misleading.. i thought it was using more than one parameter that causes a memory error.. but that's not the reason.. the reason was an incorrectly formed sql statement.. see the answer below. if create an sqlite statement that uses the same parameter more than once ie NSString* updateStmt = @"INSERT INTO search_email(..., subject, ...)" " SELECT ..., :subject, ...," " coalesce((SELECT search_email.threadID " " FROM search_email " " WHERE search_email.subject MATCH :subject2 " " )," " :uid" " )"; int subjectIndex = sqlite3_bind_parameter_index(searchEmailInsertStmt,"

Block gets released whilst in NSDictionary (ARC)

隐身守侯 提交于 2019-11-27 16:16:11
问题 I'm trying to retain a reference to a Block that's been passed in to my class by a method, to call at a later time. I'm having trouble, however, maintaining a reference to it. The obvious way, I thought, was to add it to an ivar collection, all of which are supposed to maintain strong references to their contents. But when I try to pull it back out, it's nil. The code is pretty simple: typedef void (^DataControllerCallback)(id rslt); @interface DataController : NSObject { NSMutableArray*

Why is 'no known method for selector x' a hard error under ARC?

安稳与你 提交于 2019-11-27 16:14:42
Maybe it's useful if calling a method that MyClass doesn't understand on a something typed MyClass is an error rather than a warning since it's probably either a mistake or going to cause mistakes in the future... However, why is this error specific to ARC? ARC decides what it needs to retain/release/autorelease based on the cocoa memory management conventions, which would suggest that knowing the selector's name is enough. So it makes sense that there are problems with passing a SEL variable to performSelector: , as it's not known at compile-time whether the selector is an init/copy/new

Should I need to unbind cocoa-bindings in dealloc of windowController?

一世执手 提交于 2019-11-27 15:17:41
I have window controller and view controller that use core data bindings, but I want to be able to have those views really, truly get deallocated. I then want to reset the managedObjectContext and at that point have given up as much memory as possible. I have found that I am required to unbind things which I've bound in the Nib, or the MOC keeps the Nib objects retained. The issue is this EXEC_BAD_ACCESS trace: If I do not unbind all of the bindings, even those created in Interface Builder, reset on the MOC causes an EXEC_BAD_ACCESS because bindings are attempting to reflect changes in the MOC

Could i build a ARC framework and use it in a non-ARC project?

核能气质少年 提交于 2019-11-27 15:06:10
问题 I think the title explains my question pretty well, I'm currently working on a small framework for my personal needs, and thought about building it with ARC (if thats possible at all?), and use it in old projects that were built before ARC? 回答1: Yes, with one caveat: if you have iOS 4.x as a deployment target, a supplemental library is necessary to deal with ARC-compiled code on the older runtime. For an application built using ARC, this is packaged in with the application. This is not