automatic-ref-counting

iPhone fetch data dictionary from keychain

China☆狼群 提交于 2019-11-27 10:12:04
问题 So I'm trying to convert an old project to Automatic Reference Counting. I'm trying to use the conversion tool that xCode has but it says to fix a couple things before it can convert. I have no idea how to fix this error. It's in the implementation of the keychain file. This method is the one that returns the error, specifically the line with the SecItemCopyMatching. The error I am getting says: " Cast of an indirect pointer to an Objective-C pointer to 'CFTypeRef*' (aka 'const void**') is

Possible to pass [self anyFunction] in blocks without __weak object (iOS 5 + ARC)

别来无恙 提交于 2019-11-27 09:46:55
问题 Is it possible to pass [self anyFunction] in blocks without a __weak object from self? As an example this is valid code from the System Framework: [UIView animateWithDuration:0.8 animations:^{ //Do animationStuff } completion:^(BOOL finished) { [self anyFunction]; }]; You can pass [self anyFunction] in the completion block without a warning. But if you write your own method with a completion block, the following warning occurs: capturing 'self' strongly in this block is likely to lead to a

Custom class clusters in Swift

笑着哭i 提交于 2019-11-27 09:27:17
This is a relatively common design pattern: https://stackoverflow.com/a/17015041/743957 It allows you to return a subclass from your init calls. I'm trying to figure out the best method of achieving the same thing using Swift. I do know that it is very likely that there is a better method of achieving the same thing with Swift. However, my class is going to be initialized by an existing Obj-C library which I don't have control over. So it does need to work this way and be callable from Obj-C. Any pointers would be very much appreciated. I don't believe that this pattern can be directly

Why do weak NSString properties not get released in iOS?

偶尔善良 提交于 2019-11-27 09:19:58
I wrote the following sample code to see how ARC works @property (nonatomic, weak) NSString *myString; @property (nonatomic, weak) NSObject *myObj; @end @implementation ViewController @synthesize myString = _myString; @synthesize myObj = _myObj; - (void) viewDidAppear:(BOOL)animated { NSLog(@"Appearing Obj: !%@!",self.myObj); NSLog(@"Appearing String: !%@!",self.myString); } - (void)viewDidLoad { self.myObj = [[NSObject alloc] init]; self.myString = [[NSString alloc] init]; NSLog(@"Loading Obj %@",self.myObj); NSLog(@"Loading String: !%@!",self.myString); } However surprisingly I got these

Why does ARC retain method arguments?

核能气质少年 提交于 2019-11-27 08:21:38
When compiling with ARC, method arguments often appear to be retained at the beginning of the method and released at the end. This retain/release pair seems superfluous, and contradicts the idea that ARC "produces the code you would have written anyway". Nobody in those dark, pre-ARC days performed an extra retain/release on all method arguments just to be on the safe side, did they? Consider: @interface Test : NSObject @end @implementation Test - (void)testARC:(NSString *)s { [s length]; // no extra retain/release here. } - (void)testARC2:(NSString *)s { // ARC inserts [s retain] [s length];

ios5 ARC what is the compiler flag to exclude a file from ARC?

三世轮回 提交于 2019-11-27 07:02:54
Can anyone help me remember what was the flag to tell the XCode to not use ARC for some file? I had several files in my project marked as such... Until I added another file and decided to convert that one to ARC. Sounds easy, right? I expected that I would be able to simply check a file that I want and let the XCode do it's magic. Well, not so easy, during pre-check it stripped all -Noarc flags from the files and now I need to manually re- apply the flag to several files. the moral of this story is: once your project is in ARC and you have some files marked as no ARC, do not re-run the convert

Referring to weak self inside a nested block

一曲冷凌霜 提交于 2019-11-27 06:57:52
Suppose I already create a weak self using __weak typeof(self) weakSelf = self; [self doABlockOperation:^{ ... }]; Inside that block, if I nest another block: [weakSelf doAnotherBlockOperation:^{ [weakSelf doSomething]; } will it create a retain cycle? Do I need to create another weak reference to the weakSelf? __weak typeof(self) weakerSelf = weakSelf; [weakSelf doAnotherBlockOperation:^{ [weakerSelf doSomething]; } It depends. You only create a retain cycle if you actually store the block (because self points to the block, and block points to self ). If you don't intend to store either of

NSError and __autoreleasing

老子叫甜甜 提交于 2019-11-27 06:48:40
Can someone please explain to me the purpose of having __autoreleasing in the following sample code block? - (void)execute:(NSError * __autoreleasing *)error { // do stuff, possibly assigning error if something went wrong } I removed the __autoreleasing and everything still seems to compile/run fine. I started using obj-c post ARC so I never really learned/understood all those double underscore thingamajigs. I've read the ARC transition guide , but I don't fully understand their NSError example. Consider how ARC works with variables - each reference variable has a mode (implicit or explicit):

using ARC, lifetime qualifier assign and unsafe_unretained

戏子无情 提交于 2019-11-27 06:12:20
问题 i'm a little confused about these two qualifiers... With ARC instead of using weak (i.e. if I need support iOS 4) I can use unsafe_unretained losing the auto-nil features... the final result seems to be similar to assign . Can I exchange unsafe_unretained with assign ? Are these qualifiers the same thing ? It would be really interesting any link of Apple documentation on this argument... I can find only a few rows here 回答1: Clang's technical specification of ARC goes into much more detail

Objective-C naming conventions with ARC and possible caveats

隐身守侯 提交于 2019-11-27 06:11:35
问题 I have experience with pure ARC coding. As a compiler feature it honors Objctive-C method family putting right retain/release calls whenever neeeded. All methods that start with alloc , mutableCopy , copy and new create a new object. They increase the retain count. As a consequence, ARC will release any pointer (and hence the object associated with it) when I no longer need it. I think that problems could arise when I write methods that do not follow naming conventions. For example, if I