-
Notifications
You must be signed in to change notification settings - Fork 109
[WIP] Change resource to protocol #154
base: master
Are you sure you want to change the base?
Conversation
- use carthage update --no-build
- broke macOS, tvOS, watchOS
| @@ -1,2 +1,3 @@ | |||
| github "SwiftyJSON/SwiftyJSON" ~> 3.1.4 | |||
| github "Thomvis/BrightFutures" ~> 5.0 | |||
| github "ZeWo/reflection" ~> 0.14 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick thought: updating to Swift 3 was a pain, and it seemed like the pain was exponential to the amount of dependencies involved in the project. Is it really worth adding a new dependency here? Is it absolutely required versus implementing this PR's particular reflection needs and wrapping it in an internal class?
|
Hey @mathebox, thanks for making a start at this. I was trying to pickup where you left off. |
|
|
||
| if let linkedResource = linkedResource { | ||
| if resource.value(forField: self.name) == nil || (resource.value(forField: self.name) as? Resource)?.isLoaded == false { | ||
| resource.setValue(linkedResource, forField: self.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mathebox: by the looks of it ToOneRelationship shouldn't be resolving the relationship here since the deserialise operation hasn't passed included yet...
https://github.com/mathebox/Spine/blob/741a0943fdbfd48ee149603eda1effe8678baa54/Spine/DeserializeOperation.swift#L82
|
Also seems to break the ability to sequence a bunch of BrightFuture futures: |
|
Hello guys. I have worked on a a couple ORM's and wonder if there is anything I could lend a hand with. We are looking at using this library but the "offline mode" abilities really should be moved to CoreData and thus, here we are. |
|
After doing some research into this issue for our own uses. We have come up with an idea of using spine in concert with core data, abstracted behind NSIncrementalStore. This will allow us to use core data natively with the ability to have our "back-end" be a spine-compliant API. AFNetworking once had a AFIncrementalStore that used AFRESTClient. I believe this could be easily ported to be used with spine. The only thing that would make sense to me is allow the incremental store the ability to create a "Resource" Class by inspecting a NSManagedObject for which fields it has and what types they are when it begins the store in loadMetadata. This would prevent the need for both and give a user wanting to persist with core-data a backend connected to their api. I am hoping that @wvteijlingen could guide me in the right direction as to the dynamic creation of a resource. |
|
@mmoonport hey. I've forked this PR branch into our own & have written persistence using Realm. It isn't amazing; but it works for our needs. I'm keen to write a more robust persistence layer on-top of Spine; but it seems development & activity has gone stale. |
Hi @wvteijlingen,
this is my attempt to change
Resourceto a protocol. Please have a look. The code is still kind of messy and really not ready to be merged. But the tests are passing 🎉I made the following changes
Resourceto protocolNSCodingconformance ofResource. Each implementation should handle this on its own.ZeWo/Reflection(see Support value type attributes #152) for getting and setting properties. They do not provide a dynamic framework which is necessary for carthage. So I usedcarthage update --no-buildand created a workspace for Spine and a project for Reflection.Fieldinstances due to generic types. This also preventsswitchstatements of fields of resources.Fieldimplementation to protocol-struct-combination. (We need to these protocols to hide the generic types, e.g. theRelationshipprotocol)Resourceneeds aresourceDataproperty.Next steps / further improvements
FieldDatastruct (similar toResourceData) to avoid code repetitiondescriptionanddebugDescriptiontoResourceAdditional notes
We should distinguish between
AttributeandRelationshipofResourceobjects. Currently they are returned asFieldinstances. Therefore theFieldprotocol contains some methods which are only used when working with relationships.What's do we need to support CoreData? (This should probably be moved to a separate issue.)
ResourceCollectionobjects. Maybe we could provide the links etc. via methods onResource.URL. We have to check the type of the property (String vs URL). This should be handled by theURLAttribute.Hopefully I have covered every change I made. What are your thoughts?