what is diff. b/w @property (nonatomic,assign) and @property (nonatomic,retain)
Are @property(nonatomic)ivar @property(nonatomic,assign)ivar the same or different?
i have seen in many classes that uses delegate which use this keyword assign instead of retain.
y we have use assign instead retain.
may i use assign to myclass ivar.
if i did like that then what is the meaning of it?
- Are there any good guides on custom Cocoa User Interface Design?
- How do I launch an application on system startup? (Mac OSX, Cocoa)
- Variable capture by closures in Swift and inout parameters
- How to set systems master volume from a swift app in osx
- How to do a natural sort on an NSArray?
- Cocoa: Break on every method call?
2 Solutions Collect From Internet About “what is diff. b/w @property (nonatomic,assign) and @property (nonatomic,retain)”
You should assign (= no change in retain count) delegates because you want to avoid “retain loops” (can’t think of a better word)
Take a UITableView and a UIViewController.
When you add the UITableView to your viewController you retain it. Then you assign a delegate and a datasource (which is a delegate too) to your UITableView. Usually this is your viewController.
If the tableview would retain the datasource (your viewController) there would be a “retain loop”
viewontroller retains tableview.
tableview retains viewcontroller
The viewcontrollers dealloc (where you release the tableview) would never be called because tableview would never release your viewcontroller. And the other way around.
And because of this neither would get deallocated. That’s why UITableView only assigns the datasource and the delegate. And you should do the same in your classes.
The meanings of these keywords are related to the memory management implemented by the property:
retain: the object will retain a new value set for its property, and will release old values
copy: the object will take a copy of the new value, and will release the old value
assign: the object will not do any memory management of its property value.
See “setter semantics” in the Objective-C language documentation.
In an automatic reference counting scenario, the following memory management keywords are used:
strong: the object keeps a strong (i.e. owning) reference to its property
weak: the object keeps a zeroing weak reference to its property
- Why my code cannot find digits in my String?
- Custom pin image in annotationView in iOS
- Mic input to the speaker output on an iOS device?
- How do we create a bigger center UITabBar Item
- UIWebView: HTML5 audio pauses in iOS 6 when app enters background
- Import csv data (SDK iphone)
- set a delegate for UIWebView
- Resize UIImage to 200x200pt/px
- Xcode incorrectly displaying the value of watch variables
- Autoscrolling infinite effect in .linear type of iCarousel in swift
- Adding Product Module Name to NSExtensionPrincipalClass in FinderSync plist crashes it
- how to change uiimage's image on button click in swift?
- iOS – How to check if an NSOperation is in an NSOperationQueue?
- Swift 2 parse Json as Optional to array
- Compile libtiff for iOS project to include 64bit architecture