FAQ Database Discussion Community

What's the most efficient way to store time zone info in Realm?

I have a Realm object that contains an NSDate timestamp, representing the time at which a user recorded something. I need to add time zone info to this, so that I know what the local time zone was when the user created the object (in order to do accurate date...

Format to MM:SS using NSDateComponentsFormatter

I'm trying to format to MM:SS using NSDateComponentsFormatter: let formatter = NSDateComponentsFormatter() formatter.zeroFormattingBehavior = .Pad formatter.allowedUnits = .CalendarUnitMinute | .CalendarUnitSecond let time: NSTimeInterval = 5 let timeText = formatter.stringFromTimeInterval(time) The problem is, that even though I specified .Pad, the result is 0:05 instead of 00:05. Here's a relevant piece from...

NSTimer stops when view controller is not the selected tab or not showing

I have a strange problem with my countdown timer. It fires off normally when my start button is hit, and is reinstantiated correctly when I close the app and relaunch it again. However, when I select a different tab and stay there for a while, it stops counting down, then...

Swift 2 : NSData(contentsOfURL:url) returning nil

I have a webpage address which contains a JSON file. I'm trying to access the JSON file as NSDictionary in Swift 2. Every time I call NSData(contentsOfURL:url!) where url is type of NSURL?, it returns nil. I'm using Xcode 7 Beta, and the project was first made in Xcode 6....

How to observe notifications from a different application?

I'd like to get notified when a certain application triggers an event. I'm not an Objective-C developer nor do I know the OS X APIs—so I hope this question is not too basic. My goal is to write the meta info of the currently playing song to a log file....

Can't make my activity appear in the toolbar (WWF)

I'm using Windows Workflow Fundation and I can not make my new activity appear in the toolbox in order to use it in my workflow.

How can I get screenshot from all displays on MAC?

I try to get the screenshot from all monitors connected with my MAC to one picture. I know, how I can do this if every monitor's screenshot will saved to different pictures, but it is not what I want. I found function CGGetDisplaysWithRect, but my solution don't work, because output...

NSFileManager does not properly work

I want to move 2 files with NSFileManager, but it isn't moving my files: at myfolder There are 5 text file, that i will remove all this files My code: BOOL isDir; if([[NSFileManager defaultManager] fileExistsAtPath:@"/volume/netrt/myfolder/" isDirectory:&isDir]) { [[NSFileManager defaultManager] removeItemAtPath:@"/volume/netrt/myfolder/*" error:nil]; // for delete all files [[NSFileManager defaultManager] movItemAtPath:@"/rdns/macross/text1.txt" toPath:@"/volume/netrt/myfolder/"...

How to extend the Swift Dictionary type to return a non-empty String or nil

I'm writing an extension to Dictionary so that when I give it a String key, it'll return me a String only if the value associated with the key is non-nil and not empty. extension Dictionary { subscript(key: String) -> String? { if let string = super.subscript(key) { if string.isEmpty ==...

Array has error after being retrieved from NSUserDefaults

I have a custom class for which I've implemented the NSCoder protocol. My intended data model is to store an array of these custom classes in NSUserDefaults. I encode it as NSData and store it in an array, which I store in NSUserDefaults. However when I retrieve the stored data...

Why is it okay to write acos(1.0) but not okay to write acos(1)?

In Swift, if you have two variables : var a:Int = 2 var b:Double = 3.4 And if you try to do : var c = a+b It will trigger an compile-time error, because you cannot add two variables that aren't of the same type. But still, you could do...