Last active
August 29, 2015 14:12
-
-
Save toddkramer/e2c3ce0c706db59a1244 to your computer and use it in GitHub Desktop.
ExtensionDataSharing05-ViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Books | |
class ViewController: UIViewController { | |
var booksArray = [Book]() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
saveUserDefaults() | |
savePropertyList() | |
} | |
func saveUserDefaults() { | |
let sharedDefaults = NSUserDefaults(suiteName: "group.example.DataSharing") | |
sharedDefaults?.setObject("CS Books Extension", forKey: "ExtensionTitleKey") | |
sharedDefaults?.synchronize() | |
} | |
func savePropertyList() { | |
createBooks() | |
if let filePath = SharedBooksManager.urlForSharedBooksArray() { | |
NSKeyedArchiver.archiveRootObject(booksArray, toFile: filePath) | |
} | |
} | |
func createBooks() { | |
var book = Book(title: "The C Programming Language", author: "Kernighan & Ritchie") | |
booksArray.append(book) | |
book = Book(title: "The Art of Computer Programming", author: "Donald Knuth") | |
booksArray.append(book) | |
book = Book(title: "Introduction to Algorithms", author: "Cormen, Leiserson, Rivest, & Stein") | |
booksArray.append(book) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment