Objective-C syntax


#1

Two questions regarding formatting in Objective-C. From the book:

NSCalendar *cal = [NSCalendar currentCalendar];
NSUInteger day = [cal ordinalityOfUnit:NSDayCalendarUnit
                                inUnit:NSMonthCalendarUnit
                               forDate:now];
NSLog(@"This is day %lu of the month", day);
+ (NSHost *)currentHost
- (NSString *)localizedName
  1. In the first example, NSUInteger day is not a pointer, but NSCalendar cal is. Why is that? I have read the chapter on pointers and still do not understand this.

  2. In the second example, what does this formatting indicate? It shows up in header files, Apple’s documentation, and throughout the book. What is the significance of the + and - symbols?


#2

I’m also new at obective-c and just learning it by reading this book.

  1. “ordinalityOfUnit:inUnit:forDate:” method returns result as NSInteger variable. Not pointer to it object.
  2. “+” methods are methods of class. You can call this method right from class, no need to have an object of this class. For example:

the result will be pointer to the object of NSHost class

For “-” methods you need to have an object of the class which has this method. For example:

NSString *newString = @"Hello world!"; [newString length];
We are using method with “-”

  • (NSUInteger)length;
    it’s result will be NSUInteger number 12 - the length of our string, and for calling this method we actually need to have one, it’s not enough to know just the name of the class which has this method. So we’ve created it.

That’s how I see it =)


#3

Thanks for the response. For my first question, I understand that NSUInteger returns a variable and NSCalendar returns a pointer. I guess what I’m wondering is why is that the case? If I were to write this program on my own, I wouldn’t have known to NOT make NSUInteger a pointer. Is this a hard and fast rule for the NSUInteger class? Or are there scenarios where NSUInteger would be a pointer?

I think I understand what you are saying about my second question, but I am still a little fuzzy on it.