Objective-C Sandbox

From Wikicliki
Jump to: navigation, search

A haphazardly conducted class

On 2 March 2013, I attended a slightly haphazard course "Become a NSZombie, Introduction to iOS" at Plug-In@Blk71.

Hello World

  • Open Xcode
  • You'll see templates - select single view
  • Create new "Hello World" - check local git if you want versioning - select a folder and you will have created the project
  • Uncheck storyboards, uncheck include unit tests, select universal
  • Iosoptions1.png
  • Check out the views button on top right hand corner
  • Nav on left, editor in center, utility on right, debug at bottom
  • Iosoptions.png
  • Uncheck Autolayout:

Iosoptions2.png

  • Select some tiny box (3rd on bottom row), drag a label to the panel, click on top row 4th button to see the label editing options, type hello world, and then press run.

Iosoptions3.png Iosoptions5.png

  • Published a hello world screen in the simulator

Iosoptions4.png

Traces

inside viewcontroller.m

    NSLog(@"trace");
    NSDate *dateObj = [[NSDate alloc] init];
    NSLog(@"date is %@", dateObj);
  • Syntax: MyNotes is the class:
MyNotes *notesObj = [[MyNotes alloc] init];
// pass single argument
[notesObj createNewNoteWithTItle:@"First Note"];
// pass multiple arguments
[notesObj createNewNoteWithTItle:@"First Note" andDescription:@"I Love ObjectiveC"];
  • Instructor is trying to say these are two methods.
@implementation Movie : NSObject
-(void)playMovie:(NSString *)movieName;
-(void)getMovieRatingForMovie:(NSString *)movieNamethatHasAnActor:(NSString *)actorName;
@end

The C Comparisions are lost upon me but maybe at a later date this will make more sense

getMovie //one method
getMovieRatingForMovie: thatHasAnActor //another method

COMPARED TO C which would be like

movieName(char * movieName, char * actorName);

The hungry developers in the room are hungry and confused.

Property

I've given up on trying to follow properly so i'm just googling hints now.

@property (nonatomic, strong) NSString *noteTitle; 
@property (atomic, strong) NSArray *allNoteDictionary; 
@property (nonatomic, weak) UILabel *noteLabel;

What is difference between atomic and nonatomic

The internet says: "Assuming that you are @synthesizing the method implementations, atomic vs. non-atomic changes the generated code. If you are writing your own setter/getters, atomic/nonatomic/retain/assign/copy are merely advisory. (Note: @synthesize is now the default behavior in recent versions of LLVM. There is also no need to declare instance variables; they will be synthesized automatically, too, and will have an _ prepended to their name to prevent accidental direct access).

With "atomic", the synthesized setter/getter will ensure that a whole value is always returned from the getter or set by the setter, regardless of setter activity on any other thread. That is, if thread A is in the middle of the getter while thread B calls the setter, an actual viable value -- an autoreleased object, most likely -- will be returned to the caller in A.

In nonatomic, no such guarantees are made. Thus, nonatomic is considerably faster than "atomic".

What "atomic" does not do is make any guarantees about thread safety. If thread A is calling the getter simultaneously with thread B and C calling the setter with different values, thread A may get any one of the three values returned -- the one prior to any setters being called or either of the values passed into the setters in B and C. Likewise, the object may end up with the value from B or C, no way to tell."

"By default, property accessors are atomic."

ARC

I've stopped following the class due to general confusion and inability to understand the accent.

iOS: A self directed course of study

The @autoreleasepool statement supports the Automatic Reference Counting (ARC) system. ARC provides automatic object-lifetime management for your app, ensuring that objects remain in existence for as long as they're needed and no longer.

See Also