Cocoa Keyboard Shortcuts in Dialog without an Edit Menu

Improving on that CocoaRocket solution: The following saves having to subclass NSTextField and remembering to use the subclass throughout your application; it will also enable copy, paste and friends for other responders that handle them, eg. NSTextView. Put this in a subclass of NSApplication and alter the principal class in your Info.plist accordingly. – (void) … Read more

Mac App Store Receipt Validation Code?

It is hard to provide a generic solution for Mac App Store receipt validation, mainly because this is a very sensitive piece of code that must be hard to bypass (cf. Apple documentation). These GitHub projects are very good starting points to learn about what steps must be performed in receipt validation: NPReceiptVerification ValidateStoreReceipt AppReceiptParser … Read more

Transform an NSAttributedString to plain text

If I understand you correctly you have an NSData, say data, containing an encoded NSAttributedString. To reverse the process: NSAttributedString *nas = [[NSAttributedString alloc] initWithData:data options:nil documentAttributes:NULL error:NULL]; and to get the plain text without attributes you then do: NSString *str = [nas string];

How do copy and mutableCopy apply to NSArray and NSMutableArray?

copy and mutableCopy are defined in different protocols (NSCopying and NSMutableCopying, respectively), and NSArray conforms to both. mutableCopy is defined for NSArray (not just NSMutableArray) and allows you to make a mutable copy of an originally immutable array: // create an immutable array NSArray *arr = [NSArray arrayWithObjects: @”one”, @”two”, @”three”, nil ]; // create … Read more

How to make an NSString path (file name) safe

This will remove all invalid characters anywhere in the filename based on Ismail’s invalid character set (I have not verified how complete his set is). – (NSString *)_sanitizeFileNameString:(NSString *)fileName { NSCharacterSet* illegalFileNameCharacters = [NSCharacterSet characterSetWithCharactersInString:@”/\\?%*|\”<>”]; return [[fileName componentsSeparatedByCharactersInSet:illegalFileNameCharacters] componentsJoinedByString:@””]; } Credit goes to Peter N Lewis for the idea to use componentsSeparatedByCharactersInSet: NSString – Convert … Read more

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