automatic-ref-counting

CG Gradient runs on simulator, but not on iPhone

安稳与你 提交于 2019-12-18 01:13:36
问题 I have a code that compile without problems. It runs well on the iPhone simulator, but on my device, I get an EXC_BAD_ACCESS. This happens in a helper function to draw gradient. I followed this tutorial to do it. The code I have is as follows: - (void) drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGColorRef whiteColor = [UIColor whiteColor].CGColor; CGColorRef lightGrayColor = [UIColor colorWithRed:230.0/255.0 green:230.0/255.0 blue:230.0/255.0 alpha:1.0]

Discovering at runtime which of a class' instance variables are declared __weak

↘锁芯ラ 提交于 2019-12-18 01:03:15
问题 I'm writing a tool which would benefit from knowing which of a class' instance variables are declared __weak . This information must exist somewhere at runtime, but is there any way of accessing it, documented or otherwise? (It's for a tool, so I don't care so much about it breaking with updates) 回答1: Alright, here is a sample implementation, using a custom object implementation, that does a rudimentary check to see if an iVar is weak or not: BOOL iVarIsWeak(Class cls, Ivar ivar) { id

double free*** set a breakpoint in malloc_error_break to debug in ARC

南笙酒味 提交于 2019-12-17 21:05:34
问题 I am using ARC in my application with core data and threading etc, after doing all that hard work to get core data work with threading without any crashes now I am getting a new crash with the reason- double free*** set a breakpoint in malloc_error_break to debug How am I supposed to handle this? I have no control on the objects' retain counts. 回答1: Enable Zombie Follow this link : http://iphone2020.wordpress.com/2012/02/23/capturing-exceptions-while-debugging/. This will suggest exact point

Xcode 4.2 with ARC: will my code run even on iOS devices with firmware older than 5.0?

回眸只為那壹抹淺笑 提交于 2019-12-17 20:24:51
问题 I updated my Xcode to 4.2 version, which includes the ARC technology. It seems to be a good thing, but if I enable ARC and edit my code according to Apple's suggestions, will my app build&run even on 4.3.x devices? Or only for iOS 5 ones? 回答1: ARC applications will run on OS 4.0 (4.3?) and up. On 4.3 you will lose the zeroing-weak-reference feature though. So if you rely on __weak, you shouldn't expect to work properly on < 5.0. 来源: https://stackoverflow.com/questions/7768861/xcode-4-2-with

Getting “Expected a property attribute before 'strong'” when compiling an ARC file with LLVM-GCC

为君一笑 提交于 2019-12-17 19:24:00
问题 I have a project that contains some files that are using ARC, and some are not. The ones that are not have the compiler flag that disables ARC. That works fine. I also want to make sure my library compiles for LLVM-GCC and also LLVM Compiler. I have a property like this: @property (strong, nonatomic) NSString *foo; However, when I compile in LLVM-GCC, I get: "Expected a property attribute before 'strong'" If I change strong to retain, it compiles fine. Strong also works fine in LLVM Compiler.

error 'autorelease' is unavailable: not available in automatic reference counting mode

三世轮回 提交于 2019-12-17 19:12:56
问题 I trying to make a HTTP request and parse JSON using Stig's JSON Library. I'm getting this error 'autorelease' is unavailable: not available in automatic reference counting mode when I use this code NSURLRequest *request2; request2 = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://sandbox.CompanyName.com/api/%@/users/%@/user_badges?url=CompanyName.map2.com&amount=999999999999",[information stringForKey:@"apiKey"] , [information stringForKey:@"userID"]]]];

Automatic Reference Counting: Pointer to non-const type 'NSError *' with no explicit ownership

雨燕双飞 提交于 2019-12-17 18:13:15
问题 In updating some of my code to be in compatible with the iOS 5 SDK, I attempted to refactor my code by using "Convert to Objective-C ARC" in Xcode and received an error. The error occurs on an instance variable in my .h file. NSError **_error; The error says "Pointer to non-const type 'NSError *' with no explicit ownership." How might I fix this? 回答1: When storing NSError objects in an instance variable you have to declare it as a simple pointer: @interface Foo : NSObject { NSError *_errror;

Do we need to use __weak self inside UIAnimationBlocks in ARC?

点点圈 提交于 2019-12-17 17:40:55
问题 Do we need to use __weak self inside UIAnimation Blocks as given below? Whether it will create retain cycle issue if we are not specifying self as weak? [UIView animateWithDuration:animationDuration delay:0 options:UIViewAnimationCurveEaseInOut animations:^{ [self doSomething]; } completion:^(BOOL finished) { if (finished) { [self doSomething]; } }]; I am also confused in the following scenario. Any thoughts on this? please share your comments. [self.navController

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

落爺英雄遲暮 提交于 2019-12-17 17:24:17
问题 I've begun developing my first iOS app with Xcode 4.2, and was targeting iOS 5.0 with a "utility application" template (the one that comes with a FlipsideViewController). I read that since ARC is a compile-time feature, it should be compatible with iOS 4 as well, so I attempted to target my app to 4.3, and try compiling it. When I do so, I get this error: FlipsideViewController.m: error: Automatic Reference Counting Issue: The current deployment target does not support automated __weak

EXC_BAD_ACCESS message sent to deallocated instance, but I'm using ARC?

我与影子孤独终老i 提交于 2019-12-17 15:38:53
问题 I've got an app that gets information from a SOAP web service and I want to display the results in a UITableView . I had a previous version of this app and I'm creating a new version to basically clean things up and get rid of a bunch of legacy code that's deprecated and no longer used. In the previous version, this worked well. In the new version, not so much. Basically, the current scenario is returning 3 strings that I'm trying to use as the basis for the data in my UITableView . I'm