Created
June 26, 2018 08:01
-
-
Save maltebucksch/9b35e2d0b8db13da67f87b4ff4ac501f to your computer and use it in GitHub Desktop.
Realm Sync Service: Uploadable-Extension
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
extension Uploadable where Self: Object { | |
func getId() -> String { | |
guard let primaryKey = type(of: self).primaryKey() else { | |
fatalError("Object can't be managed without a primary key") | |
} | |
guard let id = self.value(forKey: primaryKey) else { | |
fatalError("Objects primary key isn't set") | |
} | |
return String(describing: id) | |
} | |
func encoded(using jsonEncoder: JSONEncoder = JSONEncoder()) -> Data? { | |
return try? jsonEncoder.encode(self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment