Comments (11)
Good to hear you're finding it useful, even without decent documentation! Are you using it from Swift or Objective-C?
The _id
- field is actually used to construct the Core Data objectID. METCoreDataDDPClient
exposes objectIDForDocumentKey:
that you can use to get from a key (a combination of collection name and documentID) to an NSManagedObjectID
:
NSManagedObjectID *objectID = [client objectIDForDocumentKey:[METDocumentKey keyWithCollectionName:@"todos" documentID:@"bla"]];
NSManagedObject *object = [managedObjectContext objectWithID:objectID];
I'm still working out the API, so consider this a temporary solution. What is your intended usage pattern here? Where does the _id
value come from?
from meteor-ios.
It is pretty difficult without docs, I'm also new to iOS development so the difficulty is compounded, I'm basically muddling through. Do you have a swift example? I'm just trying to lookup an existing object and update some values.
from meteor-ios.
I can imagine the difficulty! Hopefully I'll find some time over the next few weeks to work on the documentation and maybe even write a tutorial. I'm in the middle of a deadline for a project and the API is still in a bit of a flux, so it'll be a while before things get stable. Core Data in itself isn't very user friendly, so I'm also working on some helper classes and extensions in Swift to make things easier.
This should work for now:
let objectID = Meteor.objectIDForDocumentKey(METDocumentKey(collectionName: "todos", documentID: "bla"))
let object = managedObjectContext.objectWithID(objectID)
from meteor-ios.
That's great, worked for me, thanks!
from meteor-ios.
Hey again, I'm now looking for a way to get the meteor ID of an object I've created. Essentially, I'm creating an object, then creating related objects and need to add the ID of the original object to the related ones. How can I get the ID of an object I already have in the managed object?
from meteor-ios.
I'm planning on simplifying this, but right now you can get the document ID of an object by using:
let object: NSManagedObject = ...
let documentID = Meteor.documentKeyForObjectID(object.objectID).documentID
I'm not sure how you're setting up relationships, but in most cases it shouldn't be necessary to connect objects manually by ID. If you define a relationship in your Core Data model and set its value, a field with the related document ID (or array of document IDs) will be managed for you.
from meteor-ios.
That would be better, can you point me to the place in your Todos example where I can get a sense of how to make that connection? (I'm using the swift version) I did some setup to relationships in the Core Data model, but I must be missing something because its not adding the IDs for me
from meteor-ios.
It should work with any properly set up Core Data relationship. There is no additional code required, you simply define the relationship in the managed object model. The only issue to keep in mind is that by default it will add IDs on both sides of the relationship. You'll have to specify 'storage = false' as user info on one of the relationship sides to suppress this (for many-to-many you need both sides).
Here are two screenshots from the Todos example:
from meteor-ios.
I have it setup essentially the same as in the screens, but it doesn't seem to be adding the values automatically. To be clear, I'm looking to have the MongoDB '_id' field for the List object inserted into the todo object as a new field on creation. Is that what should be happening?
from meteor-ios.
Yes, if you set todo.list
to a List object, a listId
field with the list _id
value should be inserted automatically into the todo document. Are you sure you're setting the list property? And have you defined it as a managed property in the Todo class?
@NSManaged var list: List!
from meteor-ios.
ah yes! I was trying to add it manually as a new field, but this is much better. Thanks!
from meteor-ios.
Related Issues (20)
- When using local IP of my macbook where meteor is running not able to connect to iPhone (ws://local IP:4000/websocket) HOT 1
- managedObjectContext nil - NSFetchedResultsController
- How to refactor METAccount so we can pass in our own service and access group to keychain?
- [IOS][1.3+] WKWebView terminated [White Screen of Death] - kills Geofence events HOT 5
- Not able to get the document ID from the collection. HOT 3
- hello @import Meteor;
- You this is written in Swift, please HOT 1
- preform complex fetches via METFetchRequest to METDatabase#executeFetchRequest:
- Mobile-config.js - App.info: Team HOT 1
- Application crash after assertionFailure in sendMessage Meteor/METDDPConnection.m:74 HOT 1
- How to listen subscription with METDDPClient HOT 1
- retry opening connection
- How to to get notified for specific collection changes?
- How to correctly use updateDocumentWithID? HOT 2
- Support meteor 1.5?
- How to log Out in Swift?
- Custom Mapping to Coredata
- Is this still being maintained? HOT 1
- How to listen to the subscriptions?
- Library not loaded: @rpath/InflectorKit.framework/InflectorKit
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-ios.