Skip to content

Instantly share code, notes, and snippets.

@nicol3a

nicol3a/store-init.swift

Last active Feb 8, 2019
Embed
What would you like to do?
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Initialize store
let context: NSManagedObjectContext = ...
let store = EventStore(context: context)
// Initialize root view controller
let viewController = EventListTableViewController(store: store)
// Initialize window...
}
}
class AddEventViewController: UIViewController {
private let store: EventStore
init(store: EventStore) {
self.store = store
super.init(nibName: nil, bundle: nil)
}
func addEventButtonTapped() {
let event = Event()
event.title = "I went to the hairdresser"
event.date = Date()
store.insert(event)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.