Objective-C Sandbox

From Wikicliki
Revision as of 05:05, 2 March 2013 by WikiSysop (talk | contribs) (The C Comparisions are lost upon me but maybe at a later date this will make more sense)

Jump to: navigation, search

A haphazardly conducted class

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);

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;

From internet - the difference between atomic and nonatomic "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."