automatic-ref-counting

assign properties, ARC and Core Foundation objects

Deadly 提交于 2019-11-26 22:59:35
问题 Edit 2. Thanks to Ken this is now working. And I even think I understand why :-) Here's the amended line: - (void) reCreatePath { CGMutablePathRef p = ::CGPathCreateMutable() ; ::CGPathMoveToPoint (p, 0, TL.x, TL.y) ; // [snip] ::CGPathAddLineToPoint (p, 0, BL.x, BL.y) ; ::CGPathCloseSubpath(p) ; self.path = p ; ::CGPathRelease(p) ; // <<== THIS IS IT!! :-) } Edit. I still don't get it. I tried Chuck suggestion: @property (nonatomic, strong) __attribute__((NSObject)) CGPathRef path ; Like so:

Xcode ARC (automatic reference counting), “release is unavailable”

余生长醉 提交于 2019-11-26 22:59:31
问题 For my first time using Xcode I was following a tutorial online. I did everything as the tutorial showed me, but I am afraid that it's too outdated. The error I encounter is: [font_attributes release]; 'release' is unavailable: not available in automatic reference counting mode ARC forbids explicit message send of 'release' My knowledge on Cocoa and Xcode is limited, but I still wish to expand my learning. How may I fix the ARC issue? 回答1: You have two options: 1) Turn off ARC for this

UIPopovercontroller dealloc reached while popover is still visible

倾然丶 夕夏残阳落幕 提交于 2019-11-26 22:32:12
问题 I assure you that I did look for an answer in SO for my question but none of them were helpful. Here I got a simple code that should present a UIImagePickerController within a UIPopoverController : -(void)takePicture:(id)sender{ UIImagePickerController *picker=[[UIImagePickerController alloc] init]; picker.delegate=self; picker.sourceType=UIImagePickerControllerSourceTypeCamera; picker.allowsEditing=YES; UIPopoverController *poc=[[UIPopoverController alloc] initWithContentViewController

weak or strong for IBOutlet and other [duplicate]

末鹿安然 提交于 2019-11-26 22:30:30
问题 This question already has an answer here: Should IBOutlets be strong or weak under ARC? 11 answers I have switched my project to ARC, and I don't understand if I have to use strong or weak for IBOutlets. Xcode do this: in interface builder, if a create a UILabel for example and I connect it with assistant editor to my ViewController , it create this: @property (nonatomic, strong) UILabel *aLabel; It uses the strong , instead I read a tutorial on RayWenderlich website that say this: But for

Under automatic reference counting, why are retain, release, and dealloc not allowed?

故事扮演 提交于 2019-11-26 22:20:52
When trying to use -retain , -release , and -dealloc while building my application using automatic reference counting in Xcode 4.2, I get an error like the following: Automatic Reference Counting forbids explicit message send of 'dealloc' Why am I seeing this error? Are -retain , -release , and -dealloc no longer allowed under automatic reference counting? Basically: When using ARC, it's all or nothing. Either the compiler is managing all of the retains/releases/deallocs for you, or it is doing nothing. You cannot intersperse your own calls to them, because the compiler wants to do it all

Does ARC work with Core Graphics objects?

吃可爱长大的小学妹 提交于 2019-11-26 22:09:24
I recently started a new project using Automatic Reference Counting (ARC). When I assigned the contents of a CALayer: UIView* view = ... UIImage* image = ... view.layer.contents = image.CGImage I got an error Implicit conversion of a non-Objective-C pointer type 'CGImageRef' to 'id' is disallowed with ARC Simply casting the CGImageRef to id hides the error, but I was wondering if the ARC still functions correctly then? Steve You should really check out the ARC videos from WWDC 2011. They are available on the developer site and open through iTunes. Especially: • Session 323 – Introducing

How do I declare an array of weak references in Swift?

青春壹個敷衍的年華 提交于 2019-11-26 21:26:17
I'd like to store an array of weak references in Swift. The array itself should not be a weak reference - its elements should be. I think Cocoa NSPointerArray offers a non-typesafe version of this. Create a generic wrapper as: class Weak<T: AnyObject> { weak var value : T? init (value: T) { self.value = value } } Add instances of this class to your array. class Stuff {} var weakly : [Weak<Stuff>] = [Weak(value: Stuff()), Weak(value: Stuff())] When defining Weak you can use either struct or class . Also, to help with reaping array contents, you could do something along the lines of: extension

NSString to CFStringRef and CFStringRef to NSString in ARC?

…衆ロ難τιáo~ 提交于 2019-11-26 21:25:19
I am trying to understand the correct way of getting an NSString from a CFStringRef in ARC? Same for going the opposite direction, CFStringRef to NSString in ARC? What is the correct way to do this without creating memory leaks? Typically NSString *yourFriendlyNSString = (__bridge NSString *)yourFriendlyCFString; and CFStringRef yourFriendlyCFString = (__bridge CFStringRef)yourFriendlyNSString; Now, if you want to know why the __bridge keyword is there, you can refer to the Apple documentation . There you will find: __bridge transfers a pointer between Objective-C and Core Foundation with no

Blocks retain cycle from naming convention?

孤者浪人 提交于 2019-11-26 21:00:56
问题 I am surprised to find the following behavior... @interface Foo : NSObject - (void)addBar:(id)aBar withCompletion:(void(^)(void))completion; @end @interface AwesomeClass : NSObject @property (strong, nonatomic) Foo *foo; - (void)doSomethingWithBar:(id)bar; @end @implementation AwesomeClass - (void)doSomethingWithBar:(id)bar { [self.foo addBar:bar withCompletion:^{ NSLog(@"%@", self.foo); }]; } In Xcode 4.6.1 I get a warning in the implementation of -doSomethingWithBar: that "Capturing 'self'

Using Non-ARC Code in an ARC-Enabled Project - Adding Facebook

徘徊边缘 提交于 2019-11-26 20:58:27
问题 When i created my project, i made it to support ARC , so my project will support iOS 4.3 and above. Now i need to integrate Twitter and Facebook to it. Both Facebook and Twitter frameworks given by the companies does not support ARC . Most of the files have dealloc, and released its variables. Some say to scrap the project and redo it disabling ARC. But, i can't afford to do this, since i have done most of the stuff. I added the FBConnect files (there were 4 of them) and added -fno-objc-arc