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
lazy var persistentContainer: NSPersistentContainer = { | |
let container = NSPersistentContainer(name: "CoreDataExample") | |
container.loadPersistentStores(completionHandler: { (storeDescription, error) in | |
if let error = error as NSError? { | |
fatalError("Unresolved error \(error), \(error.userInfo)") | |
} | |
}) | |
return container | |
}() |
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
if let appDelegate = UIApplication.shared.delegate as? AppDelegate { | |
let managedContext = appDelegate.persistentContainer.viewContext | |
if let customer: Customer = NSEntityDescription.insertNewObject(forEntityName: "Customer", into: managedContext) as? Customer { | |
customer.name = "Mike" | |
//stuff | |
} | |
} |
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 CoreData | |
//MARK: - Core Data stack | |
class CoreDataStack: NSObject { | |
static let sharedInstance = CoreDataStack() | |
static let containerName = "CoreDataExample" //CoreDataExample.xcdatamodeld | |
private override init() {} |
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 Foundation | |
import CoreData | |
protocol FetchableProtocol: class { | |
associatedtype FetchableType: NSManagedObject = Self | |
} | |
extension FetchableProtocol where Self : NSManagedObject, FetchableType == Self { | |
static func fetchAll() -> [FetchableType] { |
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 Foundation | |
import CoreData | |
@objc(Customer) | |
class Customer: CustomNSManagedObject, FetchableProtocol { | |
@NSManaged var name: String | |
@NSManaged var email: String | |
@NSManaged var password: String | |
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 Foundation | |
protocol DescribeProtocol: class { } | |
extension DescribeProtocol where Self: NSObject { | |
static var objectName: String { | |
return String(describing: self) | |
} | |
} |
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
let customer = Customer() | |
customer.name = "Mike" | |
customer.email = "mike@gmail.com" | |
customer.password = "mike123" |
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
let customerList = Customer.fetchAll() |
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
// UILabel | |
label.font = .preferredFont(forTextStyle: .headline) | |
label.adjustsFontForContentSizeCategory = true | |
// UIImageView | |
imageView.adjustsImageSizeForAccessibilityContentSizeCategory = true |
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
view.accessibilityIgnoresInvertColors = true |
OlderNewer