Skip to content

Commit 67c593c

Browse files
committed
fix crash with no entity found
affected DB fetch, including oon DB init this is kinda ugly, but can be cleaned up later...
1 parent a1d05d0 commit 67c593c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Submariner/NSManagedObjectContext+Fetch.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ extension NSManagedObjectContext {
2121
request.predicate = predicate
2222

2323
let entities = try self.fetch(request)
24-
return entities.first!
24+
if let first = entities.first {
25+
return first
26+
} else {
27+
// we can't do this instead of unwrapping failure, so do this to return nil
28+
throw NSError(domain: "com.submarinerapp.Submariner.ErrorDomain", code: 1, userInfo: [
29+
NSLocalizedDescriptionKey: "No entity with the name was found."
30+
])
31+
}
2532
}
2633
}
2734
}

0 commit comments

Comments
 (0)