-
-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: improve ParseRelation and ParseRole #328
Conversation
Thanks for opening this pull request!
|
Codecov Report
@@ Coverage Diff @@
## main #328 +/- ##
==========================================
+ Coverage 85.02% 85.11% +0.08%
==========================================
Files 114 114
Lines 12048 12116 +68
==========================================
+ Hits 10244 10312 +68
Misses 1804 1804
Continue to review full report at Codecov.
|
@jaysonng you can track this PR for adjustments. Note that though this will improve the ability of a |
yessir! I've been working with ParseRelation the past couple of days and this PR will be a big help. You rock! |
Linking this current example as the earlier one posted above links to an older revision of ParseRole. Current way to use computed property ParseRelation needs try? Parse-Swift/Sources/ParseSwift/Objects/ParseRole.swift Lines 79 to 85 in 96232f3
If you can update your message above @cbaker6, I'll just remove this one as later. thanks, |
New Pull Request Checklist
Issue Description
Currently a
ParseRelation
isn'tDecodable
. This is because decoding aParseRelation
doesn't yield a "usable"ParseRelation
out-of-the-box.See discussion here: #294 (comment)
Related issue: #n/a
Approach
Make
ParseRelation
conform toCodable
and add methods to make decoded storedParseRelation
s "usable".ParseObject
s can now contain properties of ParseRelation. In addition,ParseRelation
s can now be made fromParseObject
pointers. Also removed the need to specify the child object for aParseRelation
query as this can be type inferred by the developer.Breaking Changes to both
ParseRelation
andParseRole
. For ParseRole, the computed properties: users and roles, are now optional. The queryRoles property has been changed to queryRoles() to improve the handling of thrown errorsNote the improvements of this PR are possible because of the requirements made in
4.0.0
which require allParseObject
's to have aninit()
; giving flexibility back to the SDK by enabling it to initializeParseObject
's internally. For example, previously when creating aParseObject
, the SDK can only convert:ParseObject->Pointer<ParseObject>
, but not reverse this conversion. Since an object can be initialized, the SDK can now reverse the aforementioned conversion:Pointer<ParseObject>->ParseObject
. See more here: #315 (comment)The best way still to use
ParseRelation
is by using computed properties which is available in older and newer versions of the Swift SDK. An example of creatingParseRelation
's that are computed properties (these are usable out-of-the-box) are theusers
androles
inParseRole
:>= 4.0.0
:Parse-Swift/Sources/ParseSwift/Objects/ParseRole.swift
Lines 79 to 85 in 96232f3
< 4.0.0
:Parse-Swift/Sources/ParseSwift/Objects/ParseRole.swift
Lines 99 to 117 in c119033
and then querying the relations by using the methods available on the returned computed property.
For stored
ParseRelation
's (those decoded from the ParseServer), the "computed property" mentioned earlier still works the best, assuming you now how to construct theParseRelation
without the server. If you need to make a storedParseRelation
"usable", the following methods have been added to allParseObect
's in this PR:An example of using one of the new methods is in the Playgrounds. They are all similar. Assuming you have the
var scores: ParseRelation<Self>?
as one of your stored properties ofUser
:Parse-Swift/ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift
Lines 16 to 44 in ea631f5
You can make
scores
usable by doing the following (it's actually a lot cleaner if you useguard
, but Playgrounds only allowsguard
inside of closures because of it's structure:Parse-Swift/ParseSwift.playground/Pages/12 - Roles and Relations.xcplaygroundpage/Contents.swift
Lines 353 to 379 in ea631f5
TODOs before merging