automatic-ref-counting

-[Not A Type retain]: message sent to deallocated instance

微笑、不失礼 提交于 2019-11-27 15:00:51
I have converted my app to use ARC. Before I had the following line of code: NSArray *colors = [NSArray arrayWithObjects:startColor, endColor, nil]; Since the implicit conversion of a non-Objective-C pointer type to 'id' is disallowed with ARC, I rewrote the line like this: NSArray *colors = [NSArray arrayWithObjects:(__bridge id)startColor, (__bridge id)endColor, nil]; Everything works fine on the simulator, however on the device the app crashes on the mentioned line with the error message: -[Not A Type retain]: message sent to deallocated instance Any ideas how to solve it? Brad Larson This

fake va_list in ARC

孤人 提交于 2019-11-27 14:02:05
I need to create in an iOS application a fake va_list to pass to a NSString initWithFormat:arguments: function, this is my code: NSArray *fixedArguments = [[NSArray alloc] initWithArray:arguments]; NSRange range = NSMakeRange(0, [fixedArguments count]); va_list fakeArgList = (va_list)malloc(sizeof(NSString *) * [fixedArguments count]); __unsafe_unretained id *ptr = (__unsafe_unretained id *)fakeArgList; [fixedArguments getObjects:ptr range:range]; content = [[NSString alloc] initWithFormat:outputFormat arguments:(va_list)fakeArgList]; free(fakeArgList); The compiler complains with this message

ARC, Blocks and Retain Cycles

会有一股神秘感。 提交于 2019-11-27 13:08:03
Working on an iOS project that targets 4.0 and 5.0, using ARC. Running into an issue related to blocks, ARC and referencing an object from outside the block. Here's some code: __block AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionBlock:^ { if ([operation isCancelled]) { return; } ... do stuff ... operation = nil; }]; In this case, the compiler gives a warning that using 'operation' in the block is going to lead to a retain cycle. Under ARC, __block now retains the variable. If I add __unsafe_unretained, the compiler

SFHFKeychainUtils. iOS keychain. ARC compatible

六月ゝ 毕业季﹏ 提交于 2019-11-27 12:52:08
I was wondering if anyone that was using the SFHFKeychainUtils managed to modify them to be compatible for ARC. More exactly the NSDictionary *attributeResult = NULL; NSMutableDictionary *attributeQuery = [query mutableCopy]; [attributeQuery setObject: (id) kCFBooleanTrue forKey:(__bridge id) kSecReturnAttributes]; OSStatus status = SecItemCopyMatching((CFDictionaryRef) attributeQuery,(CFTypeRef *)(attributeResult)); I tried OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef) attributeQuery,(CFTypeRef *)(attributeResult)); also CFTypeRef subAttributeResult = (CFTypeRef *)(objc

What is the correct way to declare a readonly property for ios using ARC

自古美人都是妖i 提交于 2019-11-27 12:35:20
问题 I am new to iOS development in general and have never dealt with manual reference counting (retain, release, autorelease). As such I don't have a good understanding of what magic ARC is performing. I thought I understood until I was asked what type of ownership ( weak , strong , assign , etc) should be given to a readonly property pointing at an object, such as: @property (readonly,nonatomic) NSString* name; I read here Questions about a readonly @property in ARC that leaving off the strong /

Why can't I release an object anymore? [duplicate]

泄露秘密 提交于 2019-11-27 11:56:14
This question already has an answer here: Under automatic reference counting, why are retain, release, and dealloc not allowed? 4 answers After I updated to Xcode 4.2, I can no longer release anything. When I start typing "release" it suggest "release" but with a red line across. If I write it anyway it shows an error and displays these two messages: 'release' is unavailable: not available in automatic reference counting mode Automatic Reference Counting forbids explicit message send of 'release' Does anyone know what I can do? DarkDust You need to turn off Automatic Reference Counting . You

Capturing 'self' strongly in this block is likely to lead to a retain cycle [duplicate]

别等时光非礼了梦想. 提交于 2019-11-27 11:40:02
问题 This question already has answers here : capturing self strongly in this block is likely to lead to a retain cycle (7 answers) Closed 5 years ago . I have reqest with block. But the compiler issues a warning "Capturing 'self' strongly in this block is likely to lead to a retain cycle" __weak typeof(self) weakSelf = self; [generalInstaImage setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:data[@"images"][@"low_resolution"][@"url"]]] placeholderImage:[UIImage imageNamed:

Check for ARC in precompile

眉间皱痕 提交于 2019-11-27 10:30:44
问题 I have an iOS refactoring library that I want to work with and without the ARC compilation option. Is there a way to detect during compilation, like with an #ifdef , if ARC is available? 回答1: Yes, you can use the following: #if __has_feature(objc_arc) ... #endif Even if you're using the latest version of LLVM, this will only evaluate to true if you're compiling with the -fobjc-arc option. 来源: https://stackoverflow.com/questions/7708267/check-for-arc-in-precompile

Recursive Block Retain Cycles

主宰稳场 提交于 2019-11-27 10:22:23
问题 Will this lead to any sort of retain cycle? Is it safe to use? __block void (^myBlock)(int) = [^void (int i) { if (i == 0) return; NSLog(@"%d", i); myBlock(i - 1); } copy]; myBlock(10); myBlock = nil; 回答1: Your code does contain a retain cycle, but you can break the retain cycle at the end of the recursion by setting myBlock to nil in the recursion base case ( i == 0 ). The best way to prove this is to try it, running under the Allocations instrument, with “Discard unrecorded data upon stop”

Custom Getter & Setter iOS 5

◇◆丶佛笑我妖孽 提交于 2019-11-27 10:18:07
问题 I want to override the getter and setter in my ObjC class using ARC. .h File @property (retain, nonatomic) Season *season; .m File @synthesize season; - (void)setSeason:(Season *)s { self.season = s; // do some more stuff } - (Season *)season { return self.season; } Am I missing something here? 回答1: Yep, those are infinite recursive loops. That's because self.season = s; is translated by the compiler into [self setSeason:s]; and return self.season; is translated into return [self season]; Get