-
Notifications
You must be signed in to change notification settings - Fork 25
Defending against section.deleteOutdatedObject returning a -1 #53
Conversation
@@ -120,6 +120,7 @@ class RealmResultsCache<T: Object> { | |||
guard let section = sectionForOutdateObject(object), | |||
let sectionIndex = indexForSection(section) else { continue } | |||
let index = section.deleteOutdatedObject(object) | |||
guard index != -1 else { continue } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the -1
for a constant like NOT_FOUND?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would be great. Also, the guard for section.indexForOutdatedObject(object)
being different from -1 seems to be in many places. Consider wrapping the whole validation in one method/class.
💬 👍 |
e99e34d
to
f7bd61d
Compare
@@ -38,22 +38,22 @@ class Section<T: Object> : NSObject { | |||
return objects.indexOfObject(object) | |||
} | |||
|
|||
func delete(object: T) -> Int { | |||
func delete(object: T) -> Int? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optionals FTW!! 😍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 |
Defending against section.deleteOutdatedObject returning a -1
🎩 What? Why?
-1
when the object is not found👻 GIF