You may have noticed a steep drop in post frequency this last couple of months. The reason is that I just got married and well… I code and write this blog on my spare time and, with planning and all, have not had much of that this last months. Should be back to normal in …
Author Archives: mmv
Working with localized numbers – NSNumberFormatter Swift 2
In my case, I’m working on a csv importer and I wanted to get from the system the decimal and thousand delimiters. This is the way I do it, a workaround sure but works great: var thousandDelimiter = NSNumberFormatter.localizedStringFromNumber(NSNumber(double: 1234), numberStyle: NSNumberFormatterStyle.DecimalStyle) thousandDelimiter = thousandDelimiter.substringWithRange(thousandDelimiter.startIndex.advancedBy(1)…thousandDelimiter.startIndex.advancedBy(1)) var commaDelimiter = NSNumberFormatter.localizedStringFromNumber(NSNumber(double: 1.02), numberStyle: NSNumberFormatterStyle.DecimalStyle) commaDelimiter …
Continue reading “Working with localized numbers – NSNumberFormatter Swift 2”
Surviving in the App Store
Great article on the challenges of a small company in the App Store. Must read: http://www.theverge.com/2016/3/2/11140928/app-store-economy-apple-android-pixite-bankruptcy Marc
Using NSValueTransformers (Value Transformer) Swift 2.0
So here’s a tricky one, on my upcoming app I sometimes use View-Based TableViews. Mostly, it works like magic, but sometimes you need to use a Value Transformer in the binding to allow the table to understand how to display something. In this example, I needed to convert a NSNumber to a String (and back!). Here’s …
Continue reading “Using NSValueTransformers (Value Transformer) Swift 2.0”
3 Steps to fetch in Core Data (Swift)
1. Get the managed context: let managedObjectContext = (NSApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext! //Change AppDelegate for the name of the class of your Application Delegate 2. Set a variable to store the data: var contentsOfTransactionFetchRequest = [] 3. Fetch the data you need let fetchRequest = NSFetchRequest(entityName: “Whatever”) …
Working with NSUserDefaults in Swift 2
I was quite pleased to see than in Swift is even easier than in Objective-C. Here is how you do it: Create a variable that can access them: var userDefaults = NSUserDefaults.standardUserDefaults() Add values to dictionary: userDefaults.setObject(“StringText”, forKey: “KeyInDictionary”) Read values from dictionary: let text = userDefaults.objectForKey(“KeyInDictionary”) as! …
Mouse Down (NSEvent in Swift 2)
As I continue adding features for my upcoming app I’m starting to work with NSEvents to add actions to user interaction. I’ve been amazed at how fast is to do this in Swift. For instance, detecting where the user presses a button in your window, and then converting it to the coordinate system of a …
Switching NSViewControllers from NSWindowController
This has taken quite some time to crack as there was not that much available information online. I wanted a very simple way to change the NSViewController of a window on the fly by using code. The solution I ended up with is quite easy, on the NSWindowController I load the default NSViewController by typing …
Continue reading “Switching NSViewControllers from NSWindowController”
Random NSColor or UIColor in Swift 2
Yup, not much else to add. Here it is: let randomColor = NSColor(red: CGFloat(drand48()), green: CGFloat(drand48()), blue: CGFloat(drand48()), alpha: 1.0) For iOS developers out there just change NSColor to UIColor. Marc PS: Drand48 will create a random number between 0 and 1.
Get NSDate Day, Month or Year in Swift 2.0
Looking for Swift 3.0 version? -> Click here Well, having recharged batteries after vacation I’m back into coding! And yet again I was faced with another simple problem: how to get the day, month or year from a date. This is the simpler solution I’ve found in Swift 2: //Here I’m creating the calendar …
Continue reading “Get NSDate Day, Month or Year in Swift 2.0”