automatic-ref-counting

SudzC ARC version - objc_msgSend call causes EXC_BAD_ACCESS using 64-bit architecture

南楼画角 提交于 2019-12-17 15:33:41
问题 Edit - I've tracked the below issue to a 64-bit vs 32-bit architecture issue... see my posted answer for how I resolved I've used SudzC to generate SOAP code for a web service. They supply you with a sample application, which I was able to use successfully, both on device and simulator. I then started building out my app. I imported the SudzC generated files into a new XCode project using the blank application template (with CoreData and ARC enabled). I got the first SOAP request up and

Generate a UUID string with ARC enabled

孤人 提交于 2019-12-17 15:19:52
问题 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? 回答1: Looks fine to me. This is what I use (available as a gist) - (NSString *)uuidString { // Returns a UUID CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);

ios5 ARC what is the compiler flag to exclude a file from ARC?

前提是你 提交于 2019-12-17 08:55:38
问题 Can anyone help me remember what was the flag to tell the XCode to not use ARC for some file? I had several files in my project marked as such... Until I added another file and decided to convert that one to ARC. Sounds easy, right? I expected that I would be able to simply check a file that I want and let the XCode do it's magic. Well, not so easy, during pre-check it stripped all -Noarc flags from the files and now I need to manually re- apply the flag to several files. the moral of this

ARC memory leaks

天大地大妈咪最大 提交于 2019-12-17 07:18:31
问题 I am experiencing memory leaks linked to NSMutableArray's in a project configured to use ARC, which I thought was supposed to handle these things for you. The following code is triggering leaks of NSNumbers: NSMutableArray *myArray = [[NSMutableArray alloc] init]; NSNumber *myNumber = [NSNumber numberWithFloat:10]; [myArray addObject:myNumber]; Running the last line gives the following in the debugger: objc[1106]: Object 0x765ffe0 of class __NSCFNumber autoreleased with no pool in place -

Instance variables declared in ObjC implementation file

笑着哭i 提交于 2019-12-17 06:38:57
问题 I was watching the WWDC ARC introduction video and I saw something I've never seen in ObjC before when some Apple engineer talked about a Stack example. The following code was used for a stack example with ARC: @implementation Stack { // instance variable declared in implementation context NSMutableArray *_array; } - (id)init { if (self = [super init]) _array = [NSMutableArray array]; return self; } - (void)push:(id)x { [_array addObject:x]; } - (id)pop { id x = [_array lastObject]; [_array

NSArray of weak references (__unsafe_unretained) to objects under ARC

烂漫一生 提交于 2019-12-17 04:45:31
问题 I need to store weak references to objects in an NSArray, in order to prevent retain cycles. I'm not sure of the proper syntax to use. Is this the correct way? Foo* foo1 = [[Foo alloc] init]; Foo* foo2 = [[Foo alloc] init]; __unsafe_unretained Foo* weakFoo1 = foo1; __unsafe_unretained Foo* weakFoo2 = foo2; NSArray* someArray = [NSArray arrayWithObjects:weakFoo1, weakFoo2, nil]; Note that I need to support iOS 4.x , thus the __unsafe_unretained instead of __weak . EDIT (2015-02-18): For those

Weak NSString variable is not nil after setting the only strong reference to nil

↘锁芯ラ 提交于 2019-12-17 04:02:22
问题 I have a problem with this code : __strong NSString *yourString = @"Your String"; __weak NSString *myString = yourString; yourString = nil; __unsafe_unretained NSString *theirString = myString; NSLog(@"%p %@", yourString, yourString); NSLog(@"%p %@", myString, myString); NSLog(@"%p %@", theirString, theirString); I'm expecting all pointers to be nil at this time, but they are not and I don't understand why. The first (strong) pointer is nil but the other two are not. Why is that? 回答1: tl; dr:

Weak NSString variable is not nil after setting the only strong reference to nil

与世无争的帅哥 提交于 2019-12-17 04:02:11
问题 I have a problem with this code : __strong NSString *yourString = @"Your String"; __weak NSString *myString = yourString; yourString = nil; __unsafe_unretained NSString *theirString = myString; NSLog(@"%p %@", yourString, yourString); NSLog(@"%p %@", myString, myString); NSLog(@"%p %@", theirString, theirString); I'm expecting all pointers to be nil at this time, but they are not and I don't understand why. The first (strong) pointer is nil but the other two are not. Why is that? 回答1: tl; dr:

Custom dealloc and ARC (Objective-C)

谁说胖子不能爱 提交于 2019-12-17 03:51:29
问题 In my little iPad app I have a "switch language" function that uses an observer. Every view controller registers itself with my observer during its viewDidLoad: . - (void)viewDidLoad { [super viewDidLoad]; [observer registerObject:self]; } When the user hits the "change language" button, the new language is stored in my model and the observer is notified and calls an updateUi: selector on its registered objects. This works very well, except for when I have view controllers in a

Some questions about Automatic Reference Counting in iOS5 SDK

萝らか妹 提交于 2019-12-17 03:21:46
问题 I'm currently developing an app for iPad. The development started for iOS 4.2 and is now continuing (and I think will be completed) for iOS 4.3. I just read about ARC in iOS 5, and basically I understood that we will never need to release and retain objects anymore. My questions are: If I decide to upgrade to iOS 5, do I need to remove all [myObject retain] and [myObject release] statements from my code? If I develop a new app for iOS 5 using ARC, will I need to implement some sort of "retro