Skip to content

Instantly share code, notes, and snippets.

@artur-ios-dev
Last active August 3, 2018 09:47
Show Gist options
  • Save artur-ios-dev/a70575c91e3f40e8fcef9c62da717451 to your computer and use it in GitHub Desktop.
Save artur-ios-dev/a70575c91e3f40e8fcef9c62da717451 to your computer and use it in GitHub Desktop.
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