Variable
& Object Types
BOOL
Values:-
YES, NO
NSLog(@”The
answer is %i”, MyValue);
char
UInt8
int
32bits
(currently unless the iPhone ever moves to a 64bit chipset). If
you want to future protect pointers for a 64bit system you can use
NSInteger instead.
NSLog(@”Value
= %i”, MyValue);
long
long / unsigned long long
float
NSLog(@”Value
= %f”, MyValue);
double
NSLog(@”Value
= %f”, MyValue);
NSString
NSDate
NSObject
Most
classes in Objective-C are derived from NSObject:
NSObject *object;
object = [[NSObject alloc] init];
NSLog(@"object = %@", object);
[object release];
id
You
may be working with an object but you are not sure what that object
will be when the code executes. The id variable can be used as a sort
of placeholder for any object. It is often used in the Cocoa-Touch
frameworks and it is one of the things that contributes to the
powerful flexibility of the Objective-C programming language.
id someObject;
someObject = object;
NSLog(@"some object = %@", someObject);
Currency
A
good way is to use NSNumber and NSNumberFormatter together so that
the currency will always be localized for whatever country the device
is in.
NSNumber *MyValue = [NSNumber numberWithFloat:29.99];
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.numberStyle = kCFNumberFormatterCurrencyStyle;
NSLog(@"The cost is %@", [numberFormatter stringFromNumber:MyValue]);
[numberFormatter release];
static
Use
static as for normal C to declare static variables:
static NSString *SomeStringName;
self
(this)
self
is the address of the object running the current method. It’s
like ‘this’ in VC++. Typically it’s used so that an
object can send a message to itself:
[self SomeMethodName];
super
super
is used when you want to send a message to the self, but in it’s
super class (instead of th method being looked for in the local class
first):
[super SomeMethodName];
NSObject *object;
object = [[NSObject alloc] init];
NSLog(@"object = %@", object);
[object release];
id someObject;
someObject = object;
NSLog(@"some object = %@", someObject);
NSNumber *MyValue = [NSNumber numberWithFloat:29.99];
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.numberStyle = kCFNumberFormatterCurrencyStyle;
NSLog(@"The cost is %@", [numberFormatter stringFromNumber:MyValue]);
[numberFormatter release];
static NSString *SomeStringName;
[self SomeMethodName];
[super SomeMethodName];
No comments:
Post a Comment