Created
May 31, 2016 15:36
-
-
Save DamienBell/ea40da87cfc568e7956d6f6d264e84ed to your computer and use it in GitHub Desktop.
Handy PFObject extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PFObjectExtensions.swift | |
// Only Indie Coffee | |
// | |
// Created by Damien Bell on 5/30/16. | |
// Copyright © 2016 Damien Bell. All rights reserved. | |
// | |
import Foundation | |
import Parse | |
extension PFObject { | |
/* Because PFObject is a subclasss of NSObject, to PFObject usefully hashable we need to override the isEqual method | |
Note: not all pfObjects will have objectId's, this one is an example that | |
worked in my case. | |
You will still need to override the hashValue getter in your pfObject subclass. | |
You can define the commented code below in this file if it fits your usecase. | |
Otherwise, define that method on your PFObject subclass in a manner which always | |
provides a unique object. | |
override public var hashValue : Int { | |
get { | |
if let id = self.objectId{ | |
return id.hashValue | |
}else{ | |
return 0 | |
} | |
} | |
} | |
*/ | |
public override func isEqual(object: AnyObject?) -> Bool { | |
if (object as? PFObject)?.objectId == self.objectId { | |
return true | |
} else { | |
return super.isEqual(object) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment