automatic-ref-counting

Xcode 4.6 ARC Warning for Game Center Authentication

依然范特西╮ 提交于 2019-12-03 12:14:12
This is a new compiler warning that only showed up when I updated XCode to 4.6. My code is lifted directly from Apple's documentation (this is my iOS 6 code btw). GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) { [self setLastError:error]; if(localPlayer.authenticated){ Warning--Capturing 'localPlayer' strongly in this block is likely to lead to a retain cycle The issue is that the localPlayer object is keeping a strong reference to itself - when localPlayer is "captured" for use within the

ARC, worth it or not?

有些话、适合烂在心里 提交于 2019-12-03 12:09:58
问题 When I moved to Objective C (iOS) from C++ (and little Java) I had hard time understanding memory management in iOS. But now all this seems natural and I know retain, autorelease, copy and release stuff. After reading about ARC, I am wondering is there more benefits of using ARC or it is just that you dont have to worry about memory management. Before moving to ARC I wanted to know how worth is moving to ARC. XCode has "Convert to Objective C ARC" menu. Is the conversion is that simple

Referencing an NSOperation object in its own completion block with ARC

独自空忆成欢 提交于 2019-12-03 12:00:47
问题 I'm having difficulty converting some NSOperation code to ARC. My operation object uses a completion block, which in turn contains a GCD block that updates the UI on the main thread. Because I reference my operation object from inside its own completion block, I'm using a __weak pointer to avoid a memory leak. However, the pointer is already set to nil by the time my code runs. I've narrowed it down to this code sample. Anyone know where I went wrong, and the right way to accomplish this?

Two weak variables referencing each other in Swift?

两盒软妹~` 提交于 2019-12-03 11:39:24
I'm making another attempt today to try to understand retain cycles and weak references in Swift. Reading through the documentation , I saw the following code example where one of the referencing variables is marked as weak to prevent a retain cycle: class Person { let name: String init(name: String) { self.name = name } var apartment: Apartment? deinit { print("\(name) is being deinitialized") } } class Apartment { let unit: String init(unit: String) { self.unit = unit } weak var tenant: Person? // <---- This var is marked as 'weak' deinit { print("Apartment \(unit) is being deinitialized") }

How to know if my Xcode iPhone project is using ARC?

痴心易碎 提交于 2019-12-03 10:32:47
问题 I want to know if my Xcode iPhone project is using ARC, and I can't remember if I ticked that box when creating the project. How can I get this information? 回答1: Select your project, then Build Settings . Look for Objective-C Automatic Reference Counting in the Apple LLVM Compiler - Language section. Make sure you select the target; while you can set this in the project, the target can override it. (You can also use the search bar in Build Settings for OBJC_ARC .) Keep in mind, too, that you

App converted to ARC, now getting warnings about my properties

ぃ、小莉子 提交于 2019-12-03 10:29:52
I just converted my app to ARC , and while it builds fine, I get like 600 warnings, all pertaining to my properties. Such as: Default property attribute 'assign' not appropriate for non-gc object No 'assign', 'retain' or 'copy' attribute is specified - 'assign' is assumed After Xcode converted my code, here is what my properties look like: @property (nonatomic) EKEventStore *eventStore; @property (nonatomic) EKCalendar *defaultCalendar; @property (nonatomic) UIActionSheet *currentActionSheet; @property (nonatomic) UILabel *noEventLabel; Someone talked about needing to add strong to all of

ObjectiveC and JavaScriptCore: Will using this method of calling CallBacks cause memory issues?

假装没事ソ 提交于 2019-12-03 10:04:01
问题 DISCLAIMER: This is a long post, but could prove very valuable for those grappling with using the new ObjectiveC JavascriptCore framework and doing asynchronous coding between ObjC and JS. Hi there, I'm super new to Objective C and am integrating a javascript communication library into my iOS app. Anyway, I've been trying my hand at using the new ObjectiveC JavaScriptCore Framework introduced in iOS7. It's pretty awesome for the most part, though quite poorly documented so far. It's really

UIPopoverController dealloc getting called—ARC environment

拈花ヽ惹草 提交于 2019-12-03 09:59:07
While displaying a popover controller for a second time (after dismissing it and then re-displaying it), I get the following error: Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.' The stack trace is only a bunch of hex and the SIGABRT happens at UIApplicationMain every time. Here's the code that the button triggers: - (IBAction)createNewScore:(id)sender { if (self.pc) if (self.pc.popoverVisible) return; else // Breakpoint is hit here—crashes after this line [self.pc presentPopoverFromBarButtonItem:

Objective C - ARC - When to use @autoreleasepool

你。 提交于 2019-12-03 09:23:09
问题 I was reading a little about ARC and I saw this: @interface Address : NSObject { @public NSString *city; } @end @implementation Address - (Address*) init: (NSString*) c { city = c; return self; } - (void) dealloc { NSLog(@"Destroying address: %@", city); } @end @interface Customer : NSObject { NSString *name; Address *addr; } @end @implementation Customer - (Customer*) init: (NSString*) n withAddress: (Address*) a { //Note 1: Automatic retain on assignment name = n; addr = a; return self; } -

Subclass non-ARC file into ARC project in Xcode 4

你。 提交于 2019-12-03 08:47:20
I am using some non-ARC code in my ARC project, namely Three20. I have added all the appropriate compiler flags and all works well. However, I need to subclass some of the Three20 classes, and I'm not sure if I should add the compiler flag to my new file for non-ARC, or if the compiler will figure it out, and add the appropriate release calls. Just to recap: - ARC project in XCode 4 - Includes non-ARC code (Three20) - Need to subclass something defined in non-ARC files - Do I need to add release calls? - Do I need to add compiler flag for non-ARC in subclass? Michael, ARC is a compile time