-1

I want to show you an example of one of my header files and get your suggestions on what I could do better giving the situations below.

ARC is enabled

@property (nonatomic, assign) int some_simple_value;
@property (nonatomic, strong) NSMutableArray *someArray;
@property (nonatomic, weak) IBOutlet UIButton *someButton;
@property (nonatomic, copy) NSMutableArray *someArrayCopy
@property BOOL some_bool;

I understand what a lot of the types mean, but I don't know why I would use a given one instead of another in some cases. Also, if I know my object is only accessed by one class, should I not use nonatomic (because there's no worry of multiple threads accessing it, right?)

ANSWER

These answers helped me drastically:

What's the difference between the atomic and nonatomic attributes?

and

Objective-C declared @property attributes (nonatomic, copy, strong, weak)

Community
  • 1
  • 1
Jacksonkr
  • 29,242
  • 36
  • 164
  • 265
  • 1
    I think you'd be better off asking each item as a separate question. There's a lot here for one answer. strong vs weak has nothing to do with nonatomic vs atomic, for example, and there's a lot to be said about both subjects. – Andrew Madsen Feb 27 '13 at 23:41
  • These answers helped me drastically: http://stackoverflow.com/questions/588866/atomic-vs-nonatomic-properties and http://stackoverflow.com/questions/9859719/xcode-property-attributes-nonatomic-copy-strong-weak – Jacksonkr Feb 27 '13 at 23:54

1 Answers1

3

Well, you could read the documentation! :) But if you want a perhaps more friendly instructive explanation, I've written you one:

http://www.apeth.com/iOSBook/ch12.html#_properties_2

However, before you read that, you should really read about memory management, earlier in that chapter:

http://www.apeth.com/iOSBook/ch12.html#_memory_management

strong and weak are very different indeed; if you understand memory management and ARC, you'll know why.

matt
  • 447,615
  • 74
  • 748
  • 977