What made the difference
#property (strong, nonatomic) and #property (nonatomic, strong) in ios.
i will define iboutlet for example uilabel like this
#property (strong, nonatomic) IBOutlet UILabel *label1;
and i see many time in this site
#property (nonatomic, strong) NSString* str;
What is the difference between the two property.
There are no differences in the logic. They represent the same thing but with different order.
Usually in IBOutlets you have #property (weak, nonatomic) because it is auto generated when you ctrl+drag from interface builder.
However, most people prefer the second form because the "nonatomic" is used in most of the cases in ios and therefore it is easily ignored.
There is no difference. But in apple sample codes and most frequently we use :
#property (nonatomic, strong)
Related
I want to add my custom NSObject class to other as property, is that possible?
Class look like this:
#interface PlaceHolder : NSObject
#property (strong, nonatomic) NSString *name;
#property (strong, nonatomic) NSString *description;
#property (strong, nonatomic) NSString *webPage;
I want to make it property of my other class to initialize it once, and then work with properties - name, description. webpage and other..
Do i need to create a category? Or there is another way to achieve this?
Any advice would be appreciated, thank you.
Just add a property to the class that needs to use it
#property (strong, nonatomic) PlaceHolder *placeHolder;
I added a UITextView to storyboard that I created a property for and connected in a subview of UIView (called FieldView) in this case. The property was like this
#property (strong, nonatomic) UITextView * instructions;
That FieldView is a property of the viewController
#property (strong, nonatomic) IBOutlet FieldView *fieldView;
When I wanted to hide the UITextView *instructions with code in the viewController, I declared the property in the .h file so that I could eventually do this when a button was pressed
self.fieldView.instructions.hidden = YES;
However, xCode's giving me an error
illegal redeclaration of property in class extension FieldView, attribute must be readwrite while its primary must be readonly
When I added readwrite in both the .h and .m files
#property (weak, nonatomic, readwrite) IBOutlet UITextView *instructions;
it said `perhaps you intended this to be a readwrite redeclaration of a readonly public property
What is the correct way to do what I am trying to do?
To resolve your issue you need declare readonly property in .h file and readwrite property in .m file:
//FieldView.h
#interface FieldView
#property (nonatomic, readonly, strong) UITextView *instructions;
#end
// FieldView.m
#interface FieldView()
#property (nonatomic, readwrite, strong) IBOutlet UITextView *instructions;
#end
I Also got same issue,
If same name property is declared in .h file and you are again declaring it in extension then you will get this error.
So renaming property name will resolve the issue.
For me, I had to remove one of the properties in AppDelegate.h
Before:
#property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter;
#property (nonatomic, strong) UIWindow *window;
After:
#property (nonatomic, strong) UIWindow *window;
so I'm writing Obj-C for iOS, and something "strange" is happening..
I have an MVC, with a UITableView (private):
#interface MVC ()
#property (strong, nonatomic) IBOutlet UITableView *tableView;
#property (strong, nonatomic) CellVC *cell1;
#property (strong, nonatomic) CellVC *cell2;
#end
I load the table view up with a few custom cells. My custom cell class is actually a UIViewController... so I instantiate a few, and set cell.contentView to the corresponding CellVC.view inside the tableView:cellForRowAtIndexPath: method. My custom cell class:
#interface CellVC : UIViewController
#property (strong, nonatomic) IBOutlet UIKnob *knob1;
#property (strong, nonatomic) IBOutlet UIKnob *knob2;
#property (strong, nonatomic) IBOutlet UIKnob *knob3;
#property (strong, nonatomic) IBOutlet UIKnob *knob4;
#end
In case you're wondering, I've written a subclass of UIControl named UIKnob...
In CellVC's viewDidAppear: method, I've set a breakpoint to check the values of every knob. Each knob is non-nil, so I am happy... they have all been created.
My goal is to set MVC as the delegate of each knob. (4 knobs for each cell)
If I set a breakpoint anywhere in MVC, the value of each knob is nil??...
cell1.knob1.delegate = self;
will not work because the knobs only exist inside CellVC.m ...
Any ideas??
I keep getting random crashes saying:
Received memory warning.
(lldb)
Now after a bit of reading I have found that this is probably due to memory management, resources been fully used and none free. I thought in ARC we dont need to free up memory and release things (it wont even let us release) I thought it did it all by itself.
I have seen from some articles & threads that a possible problem is way that you define #properties so some I have:
FirstViewController
#property (strong) FilterViewController *filterViewController;
#property (weak, nonatomic) IBOutlet MKMapView *mapView;
#property(nonatomic, retain) IBOutlet UILabel *sliderValue;
#property(nonatomic, retain) NSString *passedData;
#property int selectedTime;
FilterViewController
#property (nonatomic, retain) IBOutlet UIDatePicker *datePicker;
#property (strong, nonatomic) IBOutlet UILabel *stepperValueLabel;
#property (strong) FirstViewController *firstViewController;
Your problem is Retain cycle. firstViewController object is retains filterViewController, and filterViewController object is retains firstViewController
#property (strong) FirstViewController *firstViewController; in FilterViewController
#property (strong) FilterViewController *filterViewController; in FirstViewController
I'm following along with Apple's "Hello" tutorial on iOS, and I'd like to know why it's necessary to declare the "userName" variable (to be accessed in code later). Isn't it generated by the synthesize statement?
#interface HelloWorldViewController : UIViewController {
NSString *userName;
}
- (IBAction)changeGreeting:(id)sender;
#property (weak, nonatomic) IBOutlet UILabel *label;
#property (weak, nonatomic) IBOutlet UITextField *testField;
#property (nonatomic, copy) NSString *userName;
And here's the implementation of synthesize:
#synthesize label=_label;
#synthesize testField=_testField;
#synthesize userName=_userName;
It wasn't always generated by the property/synthesize. That's a relatively new addition to Objective-C. The tutorial was probably written before this was the case.