Using frameworks in a command line tool

Unfortunately, there is no way to bundle a framework with a command-line Utility in OS X and I suspect that the framework you’re linking to is expecting to be bundled in the app bundle’s Frameworks/ directory. If you have access to the framework source code, you can compile a static library and statically link it … Read more

What’s the optimum way of storing an NSDate in NSUserDefaults?

You are needlessly complicating things. Why are you converting the date to a time interval (then the time interval to a different primitive)? Just [sharedDefaults setObject:theDate forKey:@”theDateKey”] and be done with it. NSDate is one of the “main types” supported by the PLIST format (dates, numbers, strings, data, dictionaries, and arrays), so you can just … Read more

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

Any cocoa source code for AES encryption decryption?

I use a simple category on NSData that uses the built-in CommonCrypto framework to do AES 256-bit encryption. I use this on the Mac but it should work OK on iPhone too: #import <CommonCrypto/CommonCryptor.h> @implementation NSData (AESAdditions) – (NSData*)AES256EncryptWithKey:(NSString*)key { // ‘key’ should be 32 bytes for AES256, will be null-padded otherwise char keyPtr[kCCKeySizeAES256 + … Read more

Simulate keypress using Swift

Working with Swift 3 let src = CGEventSource(stateID: CGEventSourceStateID.hidSystemState) let cmdd = CGEvent(keyboardEventSource: src, virtualKey: 0x38, keyDown: true) let cmdu = CGEvent(keyboardEventSource: src, virtualKey: 0x38, keyDown: false) let spcd = CGEvent(keyboardEventSource: src, virtualKey: 0x31, keyDown: true) let spcu = CGEvent(keyboardEventSource: src, virtualKey: 0x31, keyDown: false) spcd?.flags = CGEventFlags.maskCommand; let loc = CGEventTapLocation.cghidEventTap cmdd?.post(tap: loc) spcd?.post(tap: … Read more

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

Xcode 6 iOS Creating a Cocoa Touch Framework – Architectures issues

Based on all the responses, the post on raywenderlich.com and the gist created by Chris Conway I came up with this. Executing the following steps I was able to build a Cocoa Touch framework (including Swift and Objective-C files) that contains all architectures for both simulator and device: Create a new (Aggregate) target in your … Read more