Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I’ve mentioned several times that your variables referring to Objective-C objects are going to be pointers:
- NSString* s = @"Hello, world!";
- 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:
- - (NSString *)stringByAppendingString:(NSString *)aString
- 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:
- NSString* s1 = @"Hello, ";
- NSString* s2 = @"World!" ;
- NSString* s3 = [s1 stringByAppendingString: s2];
- The idea, then, is that although Objective-C is chock-a-b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement