automatic-ref-counting

Objective-C: blocks in ARC

萝らか妹 提交于 2019-12-07 04:01:05
问题 I'm transitioning to ARC (Automatic Reference Counting) and this document was very helpful: Transitioning to ARC Release Notes. It says: How do blocks work in ARC? Blocks “just work” when you pass blocks up the stack in ARC mode, such as in a return. You don’t have to call Block Copy any more. You still need to use [^{} copy] when passing “down” the stack into arrayWithObjects: and other methods that do a retain. Can somebody elaborate on this a little bit or give some example? I understood

How do I recover from EXC_BAD_ACCESS?

£可爱£侵袭症+ 提交于 2019-12-07 03:54:14
问题 I'm intentionally causing an EXC_BAD_ACCESS . By triggering a write to an NSObject in a read-only virtual memory page. Ideally, I'd like to catch EXC_BAD_ACCESS , mark the virtual memory page as read-write and have execution continue as it normally would have. Is this even possible? The code I've written to cause the EXC_BAD_ACCESS is below. WeakTargetObject.h (ARC) @interface WeakTargetObject : NSObject @property (nonatomic, weak) NSObject *target; @end WeakTargetObject.m (ARC)

How do I convert my Xcode project to use ARC (Automatic Reference Counting)?

℡╲_俬逩灬. 提交于 2019-12-07 03:13:29
问题 When I run Convert to Obj-C it firsts runs a Precheck. Some files I want the Precheck to ignore, and I thought I could set the compiler flag -fno-objc-arc on those files. But Precheck phase seems to ignore that flag (and reset it)...so I don't really know how to get beyond Precheck. 回答1: The first step of the pre-check has a list of all your files with checkboxes before them, just unstick the ones you do not want to convert to ARC, the migration tool will take care of setting the correct

ARC, bridged cast and GHUnit

时光总嘲笑我的痴心妄想 提交于 2019-12-07 02:48:42
问题 I'm followinng tutorial from http://gabriel.github.com/gh-unit/docs/appledoc_include/guide_testing.html. The problem is that my project uses ARC and GHUnit doesn't. I managed previous errors, but now i should do bridged cast, that i've never used, and i'm lost. NSString *string1 = @"a string"; GHAssertNotNULL(string1, nil); //error here Error description: Implicit conversion of Objective-C pointer type 'NSString *' to C pointer type 'const void *' requires a bridged cast. Any help welcome :)

how to declare variable of NSString with double pointer

落花浮王杯 提交于 2019-12-07 02:47:13
问题 I wanna use double pointer and I tried to declare like this. NSString **a; but, Xcode showed me the error "Pointer to non-const type 'NSString *' with no explicit ownership" and it couldn't be compiled. Finally I wanna do like this. NSString **a; NSString *b = @"b"; NSString *c = @"c"; a = &b; *a = c; NSLog(@"%@",b);//I wanna see "c" Let me know any advise please. 回答1: Change to this so that you can explicitly specify the ownership: NSString *__strong *a; NSString *b = @"b"; NSString *c = @"c

Dismissing Popover, [UIPopoverController dealloc] reached while popover is still visible

旧时模样 提交于 2019-12-07 02:35:52
问题 I have a UIPopoverController stored in a strong property in my View Controller. When the user rotates the iPad while the popover is visible, I dismiss the popover and set my property to nil. if (self.popover != nil) { [self.popover dismissPopoverAnimated:NO]; self.popover.delegate = nil; self.popover = nil; } When the code gets to self.popover = nil, ARC attempts to dealloc the UIPopoverController, but it crashes because it is supposedly still visible. How am I supposed to dismiss and nil out

Why does ARC autorelease when using weak references?

无人久伴 提交于 2019-12-07 01:47:25
问题 Why can't ARC use a regular release? Example: [weakObject doSomething]; From what I understand, ARC turns this into: Object *strongObject = objc_autorelease(objc_loadWeakRetained(weakObject)); [strongObject doSomething]; Why doesn't ARC do this instead?: Object *strongObject = objc_loadWeakRetained(weakObject); [strongObject doSomething]; objc_release(strongObject); I'd like to do away with as many autoreleases in ARC as possible. I do a lot of async threading with GCD and I end up having to

iOS - beginning iOS tutorial - underscore before variable?

和自甴很熟 提交于 2019-12-07 01:46:51
问题 I am starting to learn how some iOS development at the minute and I currently have the Apress beginning IOS6 book that I am working off. In chapter two there is a simple tutorial to show two buttons and a label and when a button is pressed it is shown on the label which one was pressed. I have completed the tutorial but it has raised one question that I can't find the answer to. The tutorial uses ARC (automatic reference counting) in case that makes a difference. Here is the code, The header

In ARC, why is self in init methods a consumed parameter?

会有一股神秘感。 提交于 2019-12-07 01:35:27
问题 I want to understand ARC, and I'm reading this: http://clang.llvm.org/docs/AutomaticReferenceCounting.html#consumed-parameters It says that a consumed parameter is retained before the call, and released at the end of the function (inside the function body). It then says that init... methods are effectively marked with ns_consumes_self . I don't see the point. Foo *foo = [[Foo alloc] initWithWhatever: x]; So alloc returns an object with a retain count of 1, right? Now it is retained again

ObjC ARC contraction (clang crash)

血红的双手。 提交于 2019-12-06 23:26:33
问题 I always hesitate to add a brand new question to the killer forums here, but I haven't seen anything close to this bug. Seems clang has crashed on my while compiling one of my .m files. If anyone has seen or knows of any solution for the below I'd be immensely obliged. This error occurs when I build for armv6 in a release configuration using XCode 4.4.1 But does not occur when I build for armv6 in a debug configuration , or release for armv7, armv7s or i386. The specific error is "ObjC ARC