Skip to content

Instantly share code, notes, and snippets.

@DamienBell
Created May 31, 2016 15:36
Show Gist options
  • Save DamienBell/ea40da87cfc568e7956d6f6d264e84ed to your computer and use it in GitHub Desktop.
Save DamienBell/ea40da87cfc568e7956d6f6d264e84ed to your computer and use it in GitHub Desktop.
Handy PFObject extensions
//
// 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