strong-references

How do weak and strong references look like in objective-c?

我怕爱的太早我们不能终老 提交于 2019-11-29 00:40:02
问题 Wikipedia states "In computer programming, a weak reference is a reference that does not protect the referenced object from collection by a garbage collector". How do those two types of references look like in code? Does a weak reference is a reference made by an autoreleased message? 回答1: The following answer is for the case when there is no garbage collection (such as on iOS). In the case of garbage collection, there is actually a keyword ( __weak ) to create a weak reference. A "weak"

What is difference between self.timer = nil vs [self.timer invalidate] in iOS?

本小妞迷上赌 提交于 2019-11-28 03:08:25
问题 Can anyone explain me self.timer=nil vs [self.timer invalidate] ? What exactly happens at the memory location of self.timer ? In my code self.timer=nil doesn't stops the timer but [self.timer invalidate] stops the timer. If you require my code I will update that too. 回答1: Once you have no need to run timer, invalidate timer object, after that no need to nullify its reference. This is what Apple documentation says: NSTimer Once scheduled on a run loop, the timer fires at the specified interval

weak or strong for IBOutlet and other [duplicate]

柔情痞子 提交于 2019-11-27 16:58:25
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 these two particular properties I have other plans. Instead of strong , we will declare them as weak .

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

Why isn’t my weak reference cleared right after the strong ones are gone?

人盡茶涼 提交于 2019-11-26 15:24:02
I am a little bit stubborn, but I want to understand weak and strong references well, so that's why I'm asking you once again. Consider this: __weak NSString* mySecondPointer = myText; NSLog(@"myText: %@", myText); The result is myText: (null) and it is pretty obvious - weak reference is set to null just after assignment, cause there is no strong reference to the pointed object. But in this case: __strong NSString* strongPtr = [[NSString alloc] initWithFormat:@"mYTeSTteXt %d"]; // weak pointer points to the same object as strongPtr __weak NSString* weakPtr = strongPtr; if(strongPtr == weakPtr)

Why isn’t my weak reference cleared right after the strong ones are gone?

社会主义新天地 提交于 2019-11-26 04:25:21
问题 I am a little bit stubborn, but I want to understand weak and strong references well, so that\'s why I\'m asking you once again. Consider this: __weak NSString* mySecondPointer = myText; NSLog(@\"myText: %@\", myText); The result is myText: (null) and it is pretty obvious - weak reference is set to null just after assignment, cause there is no strong reference to the pointed object. But in this case: __strong NSString* strongPtr = [[NSString alloc] initWithFormat:@\"mYTeSTteXt %d\"]; // weak