Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
[ad_1]
Right here is my code. I’ve further entities with nil attributes in Core Knowledge. after I deleted and run utility firstly, I’ve one saved object with nil attributes fetched from core information.
class RepositoryEntity {
personal var context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
func fetchRepositories() -> [RepositoryEntity] {
do {
return strive context.fetch(RepositoryEntity.fetchRequest())
} catch(let error) {
print("errr: ", error.localizedDescription)
}
return []
}
func saveObject(repo: Repository, onSuccess: () -> Void, onFailure: (_ error: String) -> Void) {
let repoEntity = RepositoryEntity(context: self.context)
repoEntity.fullName = repo.fullName
repoEntity.dateCreated = repo.dateCreated
repoEntity.url = repo.url
repoEntity.language = repo.language
repoEntity.repoDescription = repo.repoDescription
repoEntity.id = repo.id
let ownerEntity = OwnerEntity(context: self.context)
ownerEntity.ownerName = repo.proprietor.ownerName
ownerEntity.avatarUrl = repo.proprietor.avatarUrl
repoEntity.addToOwner(ownerEntity)
// Save the info
do {
strive context.save()
onSuccess()
} catch(let error) {
onFailure("One thing Happend. Attempt once more later.")
print(error.localizedDescription)
}
}
func deleteRepository(repo: Repository, onSuccess: () -> Void, onFailure: (_ error: String) -> Void) {
let repositories = fetchRepositories()
guard let deletableRepo = repositories.first(the place: {$0.id == repo.id}) else { return }
self.context.delete(deletableRepo)
do {
strive context.save()
onSuccess()
} catch(let error) {
onFailure("One thing Occurs. strive once more later.")
print(error.localizedDescription)
}
}
}
after I deleted and run utility firstly, I’ve one saved object with nil attributes fetched from core information.
[ad_2]