Last active
August 3, 2018 09:47
-
-
Save artur-ios-dev/a70575c91e3f40e8fcef9c62da717451 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
private func loadArticles() -> [Article] { | |
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { | |
return [] | |
} | |
let context = appDelegate.persistentContainer.viewContext | |
// 1 | |
let request: NSFetchRequest<Article> = Article.fetchRequest() | |
// 2 | |
// request.predicate = NSPredicate(format: "title = %@", "MEDIUM") | |
do { | |
// 3 | |
let articles = try context.fetch(request) | |
// 4 | |
articles.forEach { article in | |
guard | |
let title = article.title | |
else { | |
fatalError("This was not supposed to happen") | |
} | |
print(title) | |
} | |
return articles | |
} catch { | |
fatalError("This was not supposed to happen") | |
} | |
return [] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment