automatic-ref-counting

Using objc_getClassList under arc

懵懂的女人 提交于 2019-12-18 11:49:09
问题 Has anybody managed to use objc_getClassList under arc, short of turning arc off for the file in question? The fundamental problem is that one of the parameters is a C array of Class pointers. 回答1: This code should work under ARC: int numClasses; Class *classes = NULL; classes = NULL; numClasses = objc_getClassList(NULL, 0); NSLog(@"Number of classes: %d", numClasses); if (numClasses > 0 ) { classes = (__unsafe_unretained Class *)malloc(sizeof(Class) * numClasses); numClasses = objc

Why does the ARC migrator say that NSInvocation's -setArgument: is not safe unless the argument is __unsafe_unretained?

风格不统一 提交于 2019-12-18 11:03:07
问题 I was migrating a block of code to automatic reference counting (ARC), and had the ARC migrator throw the error NSInvocation's setArgument is not safe to be used with an object with ownership other than __unsafe_unretained on code where I had allocated an object using something like NSDecimalNumber *testNumber1 = [[NSDecimalNumber alloc] initWithString:@"1.0"]; then set it as an NSInvocation argument using [theInvocation setArgument:&testNumber1 atIndex:2]; Why is it preventing you from doing

Why does the ARC migrator say that NSInvocation's -setArgument: is not safe unless the argument is __unsafe_unretained?

一个人想着一个人 提交于 2019-12-18 11:02:27
问题 I was migrating a block of code to automatic reference counting (ARC), and had the ARC migrator throw the error NSInvocation's setArgument is not safe to be used with an object with ownership other than __unsafe_unretained on code where I had allocated an object using something like NSDecimalNumber *testNumber1 = [[NSDecimalNumber alloc] initWithString:@"1.0"]; then set it as an NSInvocation argument using [theInvocation setArgument:&testNumber1 atIndex:2]; Why is it preventing you from doing

ARC and ASIHTTPRequest

两盒软妹~` 提交于 2019-12-18 10:56:06
问题 I have a strange problem. I use ASIHTTPRequest in a iOS 5 project with ARC enabled. Since ASIHTTPRequest does not support ARC I have disabled ARC on all individual ASIHTTPRequest files. However, when I'm trying to compile my project, xcode still believes that those files are ARC-enabled and it complains. Did I do anything wrong or is that a bug in xcode? Don't tell me to convert ASIHTTPRequest to ARC-compatible code with the refactor tool. I have tried to do that and xcode complains on that

Passing blocks in Objective-C

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 10:55:14
问题 When writing a method that accepts a block as an argument, do I need to do anything special such as copying the block to the heap before executing it? For example, if I had the following method: - (void)testWithBlock:(void (^)(NSString *))block { NSString *testString = @"Test"; block(testString); } Should I do anything with block before calling it, or when entering the method? Or is the above the correct way of using the passed-in block? Also, is the following way of calling the method

Override setter with arc

别说谁变了你拦得住时间么 提交于 2019-12-18 10:00:42
问题 @interface Article : NSObject @property (nonatomic, strong) NSString *imageURLString; @end @implementation Class @synthesize imageURLString = _imageURLString; - (void)setImageURLString:(NSString *)imageURLString { _imageURLString = imageURLString; //do something else } Did I correctly override the setter when ARC is enabled? 回答1: Yes, this is correct. Also took me a while to trust that this is indeed the right thing to do. You do realize that in this case, the override is not necessary as you

BWDB SQLite wrapper for iOS ARC issues

こ雲淡風輕ζ 提交于 2019-12-18 09:45:45
问题 I am trying to use Bill Weinman's BWDB wrapper, which can be downloaded here: http://bw.org/iosdata/ I can't convert it to ARC properly, can someone more experienced then i to look at it? Main issue is va_list in insertRow & updateRow methods, idk what to do with it. The rest of the errors are easy to get rid of. Thanks in advance for any help/advice! Header file // BWDB.h // Created by Bill Weinman on 2010-09-25. // Copyright 2010 The BearHeart Group, LLC. All rights reserved. #import

Memory leak in NSString stringWithUTF8String: with ARC enabled

◇◆丶佛笑我妖孽 提交于 2019-12-18 09:37:05
问题 In my application i have enabled the ARC. But in my application following lines gives me memory leaks according to instruments. It is in ios 7.0. -(id)init{ variables = [[NSMutableArray alloc] init]; // Leak events = [[NSMutableArray alloc] init]; //Leak return self; } Update But in my app if i do something like below it does not show me any leak. But i can't add items in to the variables. -(id)init{ variables = [[[NSMutableArray alloc] init] copy]; // No Leak events = [[[NSMutableArray alloc

Weak property not zeroing using ARC

泄露秘密 提交于 2019-12-18 09:14:06
问题 I have the following simple code for an object that holds a weak reference: // interface @interface GMWeakRefObj : NSObject @property (weak) id object; @end // implementation @implementation GMWeakRefObj @synthesize object; @end When I run the following test code it fails on the second assert: NSData* d = [[NSData alloc] init]; GMWeakRefObj* weakRef = [[GMWeakRefObj alloc] init]; weakRef.object = d; NSAssert(weakRef.object != nil, @"Reference wasn't assigned"); d = nil; NSAssert(weakRef

Why does xCode 4.3 syntax highlighting break on some 64-bit projects?

对着背影说爱祢 提交于 2019-12-18 09:11:57
问题 I use XCode on many 64-bit projects, with no problem… But many times, I will find that while a target is set for 64-bit, all-but-most-basic code-completion and syntax highlighting stops working. This is the case whether ARC is enabled - or not .. (and yes, I know 32-bit isn't valid target under ARC, blah blah blah… but the funny thing is.. Syntax highlighting usually DOES work on such a misbehaving project if then switched to 32 bit mode. I have tried deleting "Derived Data", cleaning,