Skip to content

Instantly share code, notes, and snippets.

@artrmz artrmz/CoreData.swift
Last active Aug 3, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.