Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Defending against section.deleteOutdatedObject returning a -1 #53

Merged
merged 4 commits into from
Jan 5, 2016

Conversation

polqf
Copy link
Owner

@polqf polqf commented Dec 23, 2015

🎩 What? Why?

  • Defending against the possibility that section.deleteOutdatedObject returns a -1 if it does not find the object in the cache:
    • Returning nil instead of -1 when the object is not found

👻 GIF

@polqf polqf self-assigned this Dec 23, 2015
@@ -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 }
Copy link
Collaborator

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?

Copy link
Contributor

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.

@fernandogcat
Copy link
Collaborator

💬 👍

@polqf polqf force-pushed the feature/negativeIndex branch from e99e34d to f7bd61d Compare January 4, 2016 18:24
@polqf polqf added the bug label Jan 4, 2016
@@ -38,22 +38,22 @@ class Section<T: Object> : NSObject {
return objects.indexOfObject(object)
}

func delete(object: T) -> Int {
func delete(object: T) -> Int? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionals FTW!! 😍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mariabernis
Copy link
Contributor

👍

polqf added a commit that referenced this pull request Jan 5, 2016
Defending against section.deleteOutdatedObject returning a -1
@polqf polqf merged commit e8431ee into master Jan 5, 2016
@polqf polqf deleted the feature/negativeIndex branch January 5, 2016 11:30
@polqf polqf modified the milestone: 0.4.0 Jan 13, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants