NSLog a BOOL

January 23, 2011 by · 1 Comment 

Integer Value Output

NSLog(@"BOOLEAN Value: %d", (int)aBool);

String Value Output

NSLog(@"BOOLEAN Value: %@", (aBool ? @"TRUE" : @"FALSE"));

NSDate SQL like Datetime stamp

January 8, 2011 by · 1 Comment 

+(NSString *) dateTimeStamp
{
	NSDate *date = [NSDate date];
	NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
	[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
	[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
	NSString *dateString = [dateFormatter stringFromDate:date];
	[dateFormatter release];
	return dateString;
}

NSString string trim

January 8, 2011 by · 1 Comment 

- (NSString *) trim
{
	NSString *s = [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
	return s;
}

NSString string contains

January 8, 2011 by · 1 Comment 

- (BOOL)containsString:(NSString *)aString {
    return [self containsString:aString ignoringCase:NO];
}

- (BOOL)containsString:(NSString *)aString ignoringCase:(BOOL)flag {
    unsigned mask = (flag ? NSCaseInsensitiveSearch : 0);
    return [self rangeOfString:aString options:mask].length > 0;
}

Quit cocoa app on window close

January 8, 2011 by · 1 Comment 

-(BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
  return YES;
}

NSDictionary -> NSData

December 26, 2010 by · Leave a Comment 

NSError *error = nil;
NSData *data = [NSPropertyListSerialization dataFromPropertyList:theDictionaryObject format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];

NSKeyedArchiver & NSKeyedUnarchiver

December 26, 2010 by · Leave a Comment 

Archive:

NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:TheObjectToArchive forKey:@"TheArchivedObjectKey"];
[archiver finishEncoding];
[archiver release];
[data release];

Unarchive:

NSData *data = [[NSMutableData alloc] initWithData:theArchivedNSDataObject];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
id theObject = [[unarchiver decodeObjectForKey:@"TheArchivedObjectKey"] retain];
[unarchiver finishDecoding];
[unarchiver release];
[data release];

« Previous Page