Created
March 6, 2017 10:22
-
-
Save shahryarjb/8446936bddea6b22353668ee830dd127 to your computer and use it in GitHub Desktop.
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
// | |
// ViewController.swift | |
// coredatayoutube | |
// | |
// Created by shahryar tavakkoli on 06/03/2017. | |
// Copyright © 2017 shahryar tavakkoli. All rights reserved. | |
// | |
import UIKit | |
import CoreData | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let studentClassName:String = String(describing : DBstudent.self) | |
let courseClassName:String = String(describing : RELcourse.self) | |
let student:DBstudent = NSEntityDescription.insertNewObject(forEntityName: studentClassName, into: DatabaseController.getContext()) as! DBstudent | |
// MARK: - DB Test Drive | |
student.frist_name = "mojtaba" | |
student.last_name = "naseri" | |
student.old = 28 | |
let course:RELcourse = NSEntityDescription.insertNewObject(forEntityName: courseClassName, into: DatabaseController.getContext()) as! RELcourse | |
course.name = "A100" | |
// student.db_rel_tocourse = course.name["ss"] | |
// student.db_rel_tocourse(course) | |
// course.db_rel_tostudent(student) | |
DatabaseController.saveContext() | |
print(student) | |
let fechRequest:NSFetchRequest<DBstudent> = DBstudent.fetchRequest() | |
do { | |
let searchResult = try DatabaseController.getContext().fetch(fechRequest) | |
print("number result: \(searchResult.count)") | |
for dbres in searchResult as [DBstudent]{ | |
print("name \(dbres.frist_name!) - last name \(dbres.last_name!) - old:\(dbres.old)") | |
} | |
}catch { | |
print("ERORR: \(error)") | |
} | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment