Restrict NSTextField to only allow numbers

Try to make your own NSNumberFormatter subclass and check the input value in -isPartialStringValid:newEditingString:errorDescription: method. @interface OnlyIntegerValueFormatter : NSNumberFormatter @end @implementation OnlyIntegerValueFormatter – (BOOL)isPartialStringValid:(NSString*)partialString newEditingString:(NSString**)newString errorDescription:(NSString**)error { if([partialString length] == 0) { return YES; } NSScanner* scanner = [NSScanner scannerWithString:partialString]; if(!([scanner scanInt:0] && [scanner isAtEnd])) { NSBeep(); return NO; } return YES; } @end And … Read more

Easiest way to format a number with thousand separators to an NSString according to the Locale

For 10.6 this works: NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4]; [numberFormatter setNumberStyle: NSNumberFormatterDecimalStyle]; NSString *numberString = [numberFormatter stringFromNumber: [NSNumber numberWithInteger: i]]; And it properly handles localization.

What is the correct way to handle stale NSURL bookmarks?

After a lot of disappointing testing I’ve come to the following conclusions. Though logical, they’re disappointing since the resulting experience for users is far from ideal and a significant pain for developers depending on how far they’re willing to go to help users re-establish references to bookmarked resources. When I say “renew” below, I mean … Read more

Unique Identifier of a Mac?

Apple has a technote on uniquely identifying a mac. Here’s a loosely modified version of the code Apple has posted in that technote… don’t forget to link your project against IOKit.framework in order to build this: #import <IOKit/IOKitLib.h> – (NSString *)serialNumber { io_service_t platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(“IOPlatformExpertDevice”)); CFStringRef serialNumberAsCFString = NULL; if (platformExpert) { serialNumberAsCFString … Read more

Best way to do interprocess communication on Mac OS X

I am currently looking into the same questions. For me the possibility of adding Windows clients later makes the situation more complicated; in your case the answer seems to be simpler. About the options you have considered: Control files: While it is possible to communicate via control files, you have to keep in mind that … Read more

Which method of checking to see if a NSDictionary contains a particular key is faster?

A hash lookup should be faster in general than going over all the dictionary keys, creating an array from them (memory allocation is relatively expensive) and then searching the array (which can’t even be a binary search since the array is not sorted). For the sake of science, though, I made two executables that just … Read more

How to use NSIndexSet

it would be the proper way: NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 3)]; or you can use the NSMutableIndexSet for the random indexes: NSMutableIndexSet *mutableIndexSet = [[NSMutableIndexSet alloc] init]; [mutableIndexSet addIndex:0]; [mutableIndexSet addIndex:2]; [mutableIndexSet addIndex:9]; etc.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)