1

Possible Duplicate:
Atomic vs nonatomic properties

I am a beginner in objective-c. Can you tell me what is the function of following line in the code:

@property(nonatomic , retain) UITextField   *userName;
Community
  • 1
  • 1
Simer Sarao
  • 540
  • 1
  • 3
  • 9
  • 2
    this site is not a replacement for reading documentation, tutorials, and searching the web. please use a search engine and this site's search box. – Mat Apr 19 '11 at 09:50
  • 1
    http://stackoverflow.com/questions/588866/atomic-vs-nonatomic-properties – Mat Apr 19 '11 at 09:51

1 Answers1

2

This creates a property called userName of type UITextField for instances of whatever class this code is in. The (nonatomic, retain) code tells the compiler that the property will be retained every time it is accessed, and to make it thread-safe (nonatomic).

If the property is implemented with an @synthsize command, the compiler will create getter and setter methods for you, and it will make sure the getter retains your property.

Also, make sure to surround code in your questions, answers and comments with backticks like `. This will format them as code with appropriate coloring, font and highlighting.

champak256
  • 115
  • 1
  • 10
  • atomic is thread safe & non atomic is not thread safe. – user1227928 Mar 09 '15 at 05:20
  • atomic and non atomic do not guarantee anything about thread safety [Atomic vs NonAtomic](http://stackoverflow.com/questions/588866/whats-the-difference-between-the-atomic-and-nonatomic-attributes) – brl214 Mar 28 '16 at 16:05