automatic-ref-counting

Why is __strong required in fast enumeration loops with ARC

时光怂恿深爱的人放手 提交于 2020-01-10 03:07:41
问题 When I do something simialr to the following I get an error saying for (UIView* att in bottomAttachments) { if (i <= [cells count]) { att = [[UIView alloc] extraStuff] } } Fast Enumeration variables cannot be modified in ARC: declare __strong What does __strong do and why must I add it? 回答1: If a variable is declared in the condition of an Objective-C fast enumeration loop, and the variable has no explicit ownership qualifier, then it is qualified with const __strong and objects encountered

Why is __strong required in fast enumeration loops with ARC

只愿长相守 提交于 2020-01-10 03:06:05
问题 When I do something simialr to the following I get an error saying for (UIView* att in bottomAttachments) { if (i <= [cells count]) { att = [[UIView alloc] extraStuff] } } Fast Enumeration variables cannot be modified in ARC: declare __strong What does __strong do and why must I add it? 回答1: If a variable is declared in the condition of an Objective-C fast enumeration loop, and the variable has no explicit ownership qualifier, then it is qualified with const __strong and objects encountered

Correct bridging for ARC?

旧城冷巷雨未停 提交于 2020-01-09 06:07:10
问题 I have a category class for NSString. @implementation NSString (URLEncode) - (NSString *)URLEncodedString { __autoreleasing NSString *encodedString; NSString *originalString = (NSString *)self; encodedString = (__bridge_transfer NSString * ) CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)originalString, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); return encodedString; } Am I using the correct bridge transfers for ARC and the new LLVM? The original

Correct bridging for ARC?

纵饮孤独 提交于 2020-01-09 06:05:29
问题 I have a category class for NSString. @implementation NSString (URLEncode) - (NSString *)URLEncodedString { __autoreleasing NSString *encodedString; NSString *originalString = (NSString *)self; encodedString = (__bridge_transfer NSString * ) CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef)originalString, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); return encodedString; } Am I using the correct bridge transfers for ARC and the new LLVM? The original

Should I need to unbind cocoa-bindings in dealloc of windowController?

倖福魔咒の 提交于 2020-01-09 05:26:04
问题 I have window controller and view controller that use core data bindings, but I want to be able to have those views really, truly get deallocated. I then want to reset the managedObjectContext and at that point have given up as much memory as possible. I have found that I am required to unbind things which I've bound in the Nib, or the MOC keeps the Nib objects retained. The issue is this EXEC_BAD_ACCESS trace: If I do not unbind all of the bindings, even those created in Interface Builder,

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

走远了吗. 提交于 2020-01-09 05:22:06
问题 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:

How to correctly notify a delegate that the instance is no longer needed?

心已入冬 提交于 2020-01-07 06:15:54
问题 This is my pattern: 1) SpecialView creates a MessageView and holds a strong reference to it. 2) User taps a button in MessageView which causes it to fade out. MessageView then tells it's delegate, SpecialView, that it faded out completely. 3) SpecialView releases MessageView. The problem is this: - (void)fadedOut:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context { [self.delegate messageViewFadedOut:self]; // delegate releases us... // self maybe got deallocated...

NSRecursiveLock Deallocated

扶醉桌前 提交于 2020-01-07 05:19:07
问题 I Have an iOS app with multiple view controllers and ARC enabled. One of the view controllers has an IBOutlet for UIScrollView and UIPageControl . When that view controller is loaded this error is printed in the console: *** -[NSRecursiveLock dealloc]: lock (<NSRecursiveLock: 0xcb88cb0> '(null)') deallocated while still in use While trying to fix the problem, I created a symbolic breakpoint for the symbol _NSLockError with the module set to Foundation. Now Xcode breaks with breakpoint 1.1 on

Should we declare properties' ivars or let the compiler do it for us? What about weak properties?

旧城冷巷雨未停 提交于 2020-01-06 10:45:49
问题 I'd like to understand if there is any advantage in declaring properties ivars instead of letting the compiler do it for us, considering only to build code for IOS5.. I think that the best practice should be not to declare them, otherwise you should remember of things like declaring ivars as __weak if the corresponding property is declared as weak.. it is necessary to do that, right? Otherwise the weak property is assigned to a strong ivar by default and it is no more weak... 回答1: I usually

UIViewController not being dealloc-ed under the new ARC memory management

≯℡__Kan透↙ 提交于 2020-01-06 08:58:08
问题 I am pushing my UIViewController subclass onto the navigation stack; however, since it is being retained by the navigationController, I 'release' my pointer to it after pushing it onto the stack so that when it is eventually popped the viewController will be dealloc-ed. However, it's not working, the dealloc method for the viewController is never called. The code looks something like this: MyViewController *newViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"foo"];