I’m doing feasibility study for iPad application these day. Before to do so, changed my environment to the Xcode 8 with Swift 3.0.
In this application, CoreData might be used. But there are few information of usage of the CoreData with Swift 3.0. excepts below.
- What’s New in Core Data in macOS 10.12, iOS 10.0, tvOS 10.0, and watchOS 3.0
- What’s new in Core Data Swift 3.0
This is a memo to try use the CoreData with Swift3.0.
Environment:
Xcode | 8.0 |
Swift | 3.0 |
1. Making a project
- File->New->Project->SingleView Application->Next
- Product name: CoreDataSample
- [User CoreData] check->Next
2. Main.Storyboard Customize
- Defaultの ViewControllerに Navigation Controllerを Embed(Editor->Embed in->Navigation Controller)
- TableView+TableViewCellを追加
- Added some buttons
- Duplicate a View for Child View and connect with Segue.
3. Making an Entity(CoreDataSample.xcdatamodeld)
- Manager(Parent) and Staff(Child) is one to many relationship.
4. Making an Entity Class
- Selected two, Manager and Staff Entities. Editor->Create NSManagedObject Subclass …->Next->Next
- Created 4 files
Caution: After creating a files, *properties.swift has a error. because there is a unknown “Import” line. (maybe it a bag of Xcode) So, please remove it before build.
5. Add functions for CoreData
- Load
- Add
- Predict
- Remove
That’s it. Sample code is here.