I'm very new to singletons myself - but I thought I would share the code that I use to save a variable so it's accessible globally by accessing the singleton! Here is my class!

import Foundation

    private let _singletonInstance = NestedSingleton()

    @objc class NestedSingleton {

    var myManagedObjectContext:AnyObject? = nil

    class var sharedInstance: NestedSingleton {

    return _singletonInstance

Credit: http://jmduke.com/posts/singletons-in-swift/

The shared instance is created the first time you access it so I make this call in the AppDelegate:

[NestedSingleton sharedInstance].myManagedObjectContext = self.managedObjectContext;

I can then access the managedObjectContext in the Singleton anywhere in Swift like this:

class func returnMyManagedObjectContext ()->NSManagedObjectContext? {

    if let myManagedObjectContext = NestedSingleton.sharedInstance.myManagedObjectContext as? NSManagedObjectContext {

        return myManagedObjectContext

    return nil

I use this specifically to hold the managedObjectContext created in the AppDelegate. Why is this useful though? My app is a mix-and-match app that was originally created in Objective-C and I'm building new functionality in Swift.

Accessing Swift classes from Objective-C is perfectly fine, but I would like to avoid having to dig into my old Objective-C classes from Swift. This involves managing the Objective-C bridging header and creates a circular pattern of dependency between the two languages.

Hope this helps!