Saturday, September 21, 2013

Objective-C > NSString

1. Declare a new NSString object named "str1":

 NSString *str1 = [NSString stringWithFormat:@"iPhone Programming is easy];
2. Declare the new NSString object "str1" within "showMessage" method:

3. Build & Run:
<same result>
4. Declare the NSString object "str1" also likes this:
 NSString *str1 = @"iPhone Programming is super easy";
5. Build & Run again:
Before click, the original text of label1 is "Hello Nattoise".


After click, the text of label1 is changed to "iPhone Programming is super easy".



Common class method [ + ] and instance methods [ - ]:
  + stringWithFormat                                <-- Class Method [ + ]
  -  stringByAppendingString                    <-- Instance Method [ - ]
  - isEqualToString
  - length
  - intValue
  - floatValue
  - uppercaseString
  -
  -
  -
  -
  -
  -
  -
+: Class Method: 無須實體化就可以使用的方法 (生仔用only)
-: Instance Method: 需先實體化才可以使用的方法,假設str1 已經是NSString 文字實體 (生完仔, 對仔落指令)

[+] stringWithFormat: (NSString *) format




[-] (NSString *) stringByAppendingString: (NSString *) format


[-] (BOOL) isEqualToString: (NSString *) aString


[-] (NSUInteger) length



[-] (NSUInteger) intValue





[-] (float) floatValue




[-] (NSString *) uppercaseString







Reference: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

No comments:

Post a Comment