Simple get arch type

November 21, 2011 by · Leave a Comment 

#include <mach-o/arch.h>

+ (NSString *)getHostArchType
{
	const NXArchInfo *info = NXGetLocalArchInfo();
	
	switch (info->cputype) {
		case CPU_TYPE_POWERPC:
			return @"ppc";
			break;
		case CPU_TYPE_I386:
			return @"i386";
			break;
		case CPU_TYPE_POWERPC64:
			return @"ppc";
			break;
		case CPU_TYPE_X86_64:
			return @"i386";
			break;
		default:
			return @"na";
			break;
	}
}

Append String to NSTextView

May 14, 2011 by · Leave a Comment 

- (void)appendStringToTextView:(NSString *)aStr
{
	NSRange tvRange;
    tvRange = NSMakeRange ([[textView string] length], 0);
    [textView replaceCharactersInRange:tvRange withString:aStr];
	[textView scrollRangeToVisible:tvRange];
    [textView display];
}

Quickly Write NSString to file

January 27, 2011 by · Leave a Comment 

NSError* error = nil;
[@"The String to write to the file..." writeToFile:@"/tmp/aFile.txt" atomically:NO encoding:NSASCIIStringEncoding error:&error];

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;
}