Sunday, January 25, 2009

Objective C 2.0, Foundation Framework Quick Reference






Data Type Conversion Rules
The Objective-C compiler adheres to very strict rules when it comes to evaluating expressions that consist of different data types.

The following summarizes the order in which conversions take place in the evaluation of two operands in an expression:

1. If either operand is of type long double, the other is converted to long double, and that is the type of the result.

2. If either operand is of type double, the other is converted to double, and that is the type of the result.

3. If either operand is of type float, the other is converted to float, and that is the type of the result.

4. If either operand is of type _Bool, char, short int, or bit field,[1] or of an enumerated data type, it is converted to int.

5. If either operand is of type long long int, the other is converted to long long int, and that is the type of the result.

6. If either operand is of type long int, the other is converted to long int, and that is the type of the result.

7. If this step is reached, both operands are of type int, and that is the type of the result.
































Common NSString Methods
MethodDescription
+(id) stringWithContentsOfFile: path encoding: enc error: err Creates a new string and sets it to the path contents of a file specified by path using character encoding enc, returning error in err if non-nil
+(id) stringWithContentsOfURL: url encoding: enc error: err Creates a new string and sets it to the contents of url using character encoding enc, returning error in err if non-nil
+(id) string Creates a new empty string
+(id) stringWithString: nsstring Creates a new string, setting it to nsstring
-(id) initWithString: nsstring Sets a newly allocated string to nsstring
-(id) initWithContentsOfFile: path encoding: enc error: err Sets a string to the contents of a file specified by path
-(id) initWithContentsOfURL: url encoding enc error: err Sets a string to the contents of url (NSURL *) url using character encoding enc, returning error in err if non-nil
-(NSUInteger) length Returns the number of characters in the string
-(unichar) characterAtIndex: i Returns the Unicode character at index i
-(NSString *) substringFromIndex: i Returns a substring from the character at i to the end
-(NSString *) substringWithRange: range Returns a substring based on a specified range
-(NSString *) substringToIndex: i Returns a substring from the start of the string up to the character at index i
-(NSComparator *) caseInsensitiveCompare: nsstring Compares two strings, ignoring case
-(NSComparator *) compare: nsstring Compares two strings
-(BOOL) hasPrefix: nsstring Tests whether a string begins with nsstring
-(BOOL) hasSuffix: nsstring Tests whether a string ends with nsstring
-(BOOL) isEqualToString: nsstring Tests whether two strings are equal
-(NSString *) capitalizedString Returns a string with the first letter of every word capitalized (and the remaining letters in each word converted to lower case)
-(NSString *) lowercaseString Returns a string converted to lower case
-(NSString *) uppercaseString Returns a string converted to upper case
-(const char *) UTF8String Returns a string converted to a UTF-8 C-style character string
-(double) doubleValue Returns a string converted to a double
-(float) floatValue Returns a string converted to a floating value
-(NSInteger) integerValue Returns a string converted to an NSInteger integer
-(int) intValue Returns a string converted to an integer












Common NSMutableString Methods
MethodDescription
+(id) stringWithCapacity: size Creates a string initially containing size characters.
-(id) initWithCapacity: size Initializes a string with an initial capacity of size characters.
-(void) setString: nsstring Sets a string to nsstring.
-(void) appendString: nsstring Appends nsstring to the end of the receiver.
-(void) deleteCharactersInRange: range Deletes characters in a specified range.
-(void) insertString: nstring atIndex: i Inserts nsstring into the receiver starting at index i.
-(void) replaceCharactersInRange: range withString: nsstring Replaces characters in a specified range with nsstring.
-(void) replaceOccurrencesOf String: nsstring withString: nsstring2 options: opts range: range Replaces all occurrences of nsstring with nsstring2 within a specified range and according to options opts. Options can include a bitwise-ORed combination of NSBackwardsSearch (the search starts from the end of range), NSAnchoredSearch (nsstring must match from the beginning of the range only), NSLiteralSearch (performs a byte-by-byte comparison), and NSCaseInsensitiveSearch.













Common NSArray Methods
MethodDescription
+(id) arrayWithObjects: obj1, obj2, ... nil Creates a new array with obj1, obj2, ... as its elements
-(BOOL) containsObject: obj Determines whether the array contains obj (uses the isEqual: method)
-(NSUInteger) count Indicates the number of elements in the array
-(NSUInteger) indexOfObject: obj Specifies the index number of the first element that contains obj (uses the isEqual: method)
-(id) objectAtIndex: i Indicates the object stored in element i
-(void) makeObjectsPerform Selector: (SEL) selector Sends the message indicated by selector to every element of the array
-(NSArray *) sortedArrayUsing Selector: (SEL) selector Sorts the array according to the comparison method specified by selector
-(BOOL) writeToFile: path automically: (BOOL) flag Writes the array to the specified file, creating a temporary file first if flag is YES













Common NSMutableArray Methods
MethodDescription
+(id) array Creates an empty array
+(id) arrayWithCapacity: size Creates an array with a specified initial size
-(id) initWithCapacity: size Initializes a newly allocated array with a specified initial size
-(void) addObject: obj Adds obj to the end of the array
-(void) insertObject: obj atIndex: i Inserts obj into element i of the array
-(void) replaceObjectAtIndex: i withObject: obj Replaces element i of the array with obj
-(void) removeObject: obj Removes all occurrences of obj from the array
-(void) removeObjectAtIndex: i Removes element i from the array, moving down elements i+1 through the end of the array
-(void) sortUsingSelector: (SEL) selector Sorts the array based on the comparison method indicated by selector











Common NSDictionary Methods
MethodDescription
+(id) dictionaryWithObjectsAndKeys: obj1, key1, obj2, key2, ..., nil Creates a dictionary with key-object pairs {key1, obj1}, {key2, obj2}, ...
-(id) initWithObjectsAndKeys: obj1, key1, obj2, key2,..., nil Initializes a newly allocated dictionary with key-object pairs {key1, obj1}, {key2, obj2}, ...
-(unsigned int) count Returns the number of entries in the dictionary
-(NSEnumerator *) keyEnumerator Returns an NSEnumerator object for all the keys in the dictionary
-(NSArray *) keysSortedByValueUsingSelector: (SEL) selector Returns an array of keys in the dictionary sorted according to the comparison method selector specifies
-(NSEnumerator *) objectEnumerator Returns an NSEnumerator object for all the values in the dictionary
-(id) objectForKey: key Returns the object for the specified key









Common NSMutableDictionary Methods
MethodDescription
+(id) dictionaryWithCapacity: size Creates a mutable dictionary with an initial specified size
-(id) initWithCapacity: size Initializes a newly allocated dictionary to be of an initial specified size
-(void) removeAllObjects Removes all entries from the dictionary
-(void) removeObjectForKey: key Removes the entry for the specified key from the dictionary
-(void) setObject: obj forKey: key Adds obj to the dictionary for the key key and replaces the value if key already exists













Common NSSet Methods
MethodDescription
+(id) setWithObjects: obj1, obj2, ..., nil Creates a new set from the list of objects
-(id) initWithObjects: obj1, obj2, ..., nil Initializes a newly allocated set with a list of objects
-(NSUInteger) count Returns the number of members in the set
-(BOOL) containsObject: obj Determines whether the set contains obj
-(BOOL) member: obj Determines whether the set contains obj (using the isEqual: method)
-(NSEnumerator *) objectEnumerator Returns an NSEnumerator object for all the objects in the set
-(BOOL) isSubsetOfSet: nsset Determines whether every member of the receiver is present in nsset
-(BOOL) intersectsSet: nsset Determines whether at least one member of the receiver appears in nsset
-(BOOL) isEqualToSet: nsset Determines whether the two sets are equal












Common NSMutableSet Methods
MethodDescription
-(id) setWithCapacity: size Creates a new set with an initial capacity to store size members
-(id) initWithCapacity: size Sets the initial capacity of a newly allocated set to size members
-(void) addObject: obj Adds obj to the set
-(void) removeObject: obj Removes obj from the set
-(void) removeAllObjects Removes all members of the receiver
-(void) unionSet: nsset Adds each member of nsset to the receiver
-(void) minusSet: nsset Removes all members of nsset from the receiver
-(void) intersectSet: nsset Removes all members from the receiver that are not also in nsset















Common NSFileManager Methods
MethodDescription
-(NSData *) contentsAtPath: path Reads data from a file
-(NSData *) createFileAtPath: path contents: (NSData *) data attributes: attr Writes data to a file
-(BOOL) removeFileAtPath: path handler: handler Removes a file
-(BOOL) movePath: from toPath: to handler: handler Renames or moves a file (to cannot already exist)
-(BOOL) copyPath: from toPath: to handler: handler Copies a file (to cannot already exist)
-(BOOL) contentsEqualAtPath: path1 andPath: path2 Compares contents of two files
-(BOOL) fileExistsAtPath: path Tests for file existence
-(BOOL) isReadableFileAtPath: path Tests whether file exists and can be read
-(BOOL) isWritableFileAtPath: path Tests whether file exists and can be written
-(NSDictionary *) fileAttributesAtPath: path traverseLink: (BOOL) flag Gets attributes for file
-(BOOL) changeFileAttributes: attr atPath: path Changes file attributes















Common Path Utility Methods
MethodDescription
+(NSString *) pathWithComponents: components Constructs a valid path from elements in components
-(NSArray *) pathComponents Deconstructs a path into its constituent components
-(NSString *) lastPathComponent Extracts the last component in a path
-(NSString *) pathExtension Extracts the extension from the last component in a path
-(NSString *) stringByAppendingPathComponent: path Adds path to the end of an existing path
-(NSString *) stringByAppendingPathExtension: ext Adds the specified extension to the last component in the path
-(NSString *) stringByDeletingLastPathComponent Removes the last path component
-(NSString *) stringByDeletingPathExtension Removes the extension from the last path component
-(NSString *) stringByExpandingTildeInPath Expands any tildes in the path to the user's home directory (~) or a specified user's home directory (~user)
-(NSString *) stringByResolvingSymlinksInPath Attempts to resolve symbolic links in the path
-(NSString *) stringByStandardizingPath Standardizes a path by attempting to resolve ~, ..(parent directory), .(current directory), and symbolic links



Common Resources Path for iPhone
NSBundle Select all

NSString *myinfoplist = [ [ NSString alloc ] initWithFormat: @"%@/Info.plist", [[NSBundle mainBundle] resourcePath] ];
NSLog (@"Documents Folder is %@",[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]);
NSString *myFile = [ [ NSString alloc ] initWithFormat: @"%@/Documents/file.db", NSHomeDirectory() ];

NSDirectoryEnumerator *dirEnum;
NSString *file;
dirEnum = [ [ NSFileManager defaultManager ] enumeratorAtPath:NSHomeDirectory()];
while (file = [ dirEnum nextObject ]) {
NSLog(@"%@",[NSHomeDirectory() stringByAppendingPathComponent:file]);
/*
Documents/
Library/
Preferences/
MyApp.app/
*/
}






No comments: