Advertisement
kntreadway

Untitled

Jun 6th, 2011
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. I’ve mentioned several times that your variables referring to Objective-C objects are going to be pointers:
  2.  
  3. NSString* s = @"Hello, world!";
  4.  
  5. Although it is common to speak loosely of s as an NSString (or just as a string), it is actually an NSString* — a pointer to an NSString. Therefore, when a C function or an Objective-C method expects an NSString* parameter, there’s no problem, because that’s exactly what you’ve got. For example, one way to concatenate two NSStrings is to call the NSString method stringByAppendingString: (that’s not a misprint; the colon is part of the name), which the documentation tells you is declared as follows:
  6.  
  7. - (NSString *)stringByAppendingString:(NSString *)aString
  8.  
  9. The space between the class name and the asterisk is optional, so this declaration is telling you (after you allow for the Objective-C syntax) that this method expects one NSString* parameter and returns an NSString*. That’s splendid because those kinds of pointers are just what you’ve got and just what you want. So this code would be legal:
  10.  
  11. NSString* s1 = @"Hello, ";
  12. NSString* s2 = @"World!" ;
  13. NSString* s3 = [s1 stringByAppendingString: s2];
  14.  
  15. The idea, then, is that although Objective-C is chock-a-b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement