Swiftで遊ぼう! - 622 - CoreDataDemo3 - 4
- Swiftで遊ぼう!の前書き-> Life-LOG OtherSide
- Swift2.1 & Xcode7.1対応の日本語版アップルチュートリアル!
- Table View実装チュートリアルをXcode7.2.1で解説
- Core Data シンプルチュートリアル
- 私の本業、オフィシャルなブログ-> Life-LOG
ViewControllerのコードを書いています。
次にviewDidLoad()メソッド内のコーディングをする。アプリが立ち上がった時にNavigation Controllerのタイトルに「Students」という文字列を表示させて、データベースからStudentエンティティデータを読み込むコードを書きます。
override func viewDidLoad() { super.viewDidLoad() title = "Students" let delegate = UIApplication.sharedApplication().delegate as! AppDelegate let context = delegate.managedObjectContext let request = NSFetchRequest(entityName: "Student") do { students = try context.executeFetchRequest(request) as! [Student] } catch let error as NSError { print("Problem with loading Data, Error type: \(error)") } }
もう何度も出てきているパターンです。見直さなくてもコードのパターンを覚えました。
今日はこれだけ。