CoreData relationships sample

1,020 views
Skip to first unread message

jj

unread,
Jun 9, 2012, 11:52:06 AM6/9/12
to rubym...@googlegroups.com
I've just uploaded a sample demonstrating how to create CoreData relationships programmatically in rubymotion.

https://github.com/caramdache/games

Enjoy,

Jim Nanney

unread,
Jun 9, 2012, 3:36:01 PM6/9/12
to rubym...@googlegroups.com
Thank you for sharing this.  I'm still trying to figure out Core Data, and even tougher is doing it without Xcode, and the data modeler.  Even Hillegass' and Marcus Zarra's books depend on them.

JJ

unread,
Jun 9, 2012, 5:24:49 PM6/9/12
to rubym...@googlegroups.com
It turns out to be simpler without Xcode -or, said otherwise, having had to expand Laurent's example to support relationships, I had to understand core data from the inside, i.e. from the meta programming point of view - turns out to be quite useful. This is an area of the Apple doc I had never to dig through before and I now understand core data better. 

The Games sample uses two methods to retrieve objects. The simplest one fires an NSRequest and returns the results as array (.objects).

The more complex one returns an NSFetchedResultsController (.controller). Think of it as an impedance adapter than provides an UITableviewController like interface and splits objects by section for you (this would a hash in ruby).

Read the doc for these two classes. 

What I like about creating core data models in ruby is that I do not have to open Xcode again. It suddenly feels a lot lighter. YMMV

Mac Fanatic

unread,
Jun 20, 2012, 10:43:49 PM6/20/12
to rubym...@googlegroups.com
I'm using Nitron (after fighting with motion-record) and just plain CoreData & have to say its awesome.

There is a tutorial on the main Nitron project, which supports the Xcode data modeler. Relationships are supported, and I have several pull requests for useful features. Using this in an iPad app under dev currently.

Mac Fanatic

unread,
Jun 20, 2012, 10:44:15 PM6/20/12
to rubym...@googlegroups.com

Jim Nanney

unread,
Jun 22, 2012, 9:51:55 AM6/22/12
to rubym...@googlegroups.com
Nitron is neat, but if I can help it,  I never want to open Xcode again.

On Wednesday, June 20, 2012 9:44:15 PM UTC-5, Mac Fanatic wrote:
Link - https://github.com/macfanatic/nitron

Matt Green

unread,
Jun 22, 2012, 1:25:15 PM6/22/12
to rubym...@googlegroups.com
I feel the same way. 

We're working toward text-based workflows while providing something that works in the interim. I'm keen on supporting iCloud and CoreData, and that requires lightweight migrations.

Steve Ross

unread,
Jun 22, 2012, 7:16:01 PM6/22/12
to rubym...@googlegroups.com
I can understand some loathing for Xcode or a sense of dirtiness messing around with magic glue, but is there a technical aspect to the Nitron approach that will handicap migrations or otherwise inject noise/overhead into the app?

Thanks

--

Matt Green

unread,
Jun 27, 2012, 9:36:18 AM6/27/12
to rubym...@googlegroups.com
No.

I've begun work on an XCode-less version of CoreData support that generates .xcdatamodeld files via rake tasks. This creates a nice workflow that is very similar to that of Rails:

1. Write models, put them in app/models
2. rake dm:migrate # scans models, generates xcdatamodeld, and compares to existing one. If new, saves new version and activates it
3. rake


Is this what you're looking for?

Jim Nanney

unread,
Jun 27, 2012, 10:14:13 PM6/27/12
to rubym...@googlegroups.com
Fantastic! Other than not wanting to deal with Xcode, there is no good reason I can come up with.  But it feels great to use textmate, ruby motion and the simulator only. 

Steve Ross

unread,
Jul 26, 2012, 3:38:56 PM7/26/12
to rubym...@googlegroups.com
I'm trying to use relationships in nitron and you mentioned that you had pull requests in that support them. Were they incorporated? In any case, I may switch to your branch and merge my own changes. Can you give me an example of the syntax for relationships? I.e., does it work like:

class Owner
  has_many
:tasks
end


class  Task
  belongs_to
:owner
end


...


Owner.first.tasks << Task.create(:task => 'Walk the dog')



Mind you, I'm just making this stuff up. What I'm really looking for is some guidance to get me past the single-table stuff that seems so simple using Nitron.

Thanks,

Steve

Steve Ross

unread,
Jul 26, 2012, 3:55:26 PM7/26/12
to rubym...@googlegroups.com
I should mention, this was intended as a follow-up to Matt Green and Mac Fanatic's posts and only relates to Nitron and it's use of the XCode data modeler (which I agree is not optimal in the dev workflow, but right now works...).

Steve

--
 
 
 

Bodacious

unread,
Sep 12, 2012, 5:47:07 PM9/12/12
to rubym...@googlegroups.com
I know this is an old post but have any of you guys tried MotionData? Looks great but I can't get it to load without crashing :/

Steve Ross

unread,
Sep 12, 2012, 7:27:20 PM9/12/12
to rubym...@googlegroups.com
I am working on some of the issues in MotionData and would love it if you would raise issues on GitHub. Right now, I'm not building gems each time I do a push. Too much churn. So if you clone the project and put:

require "/path/to/motion_model/lib/motion_model.rb"

in your Rakefile instead of requiring the gem or listing it in your gemfile, you can stay right on the bleeding edge. Also, if you watch the project, you can see when commits happen so you can decide whether to pull fixes.

Steve


--
 
 
 

Eloy Durán

unread,
Sep 20, 2012, 12:27:24 PM9/20/12
to rubym...@googlegroups.com
Can you tell me more about the crash you are experiencing?

--
 
 
 

Eloy Durán

unread,
Sep 20, 2012, 12:28:47 PM9/20/12
to rubym...@googlegroups.com
Steve, did you really mean MotionData? Because you code sample is regarding MotionModel. If it is about MotionData, I’d love to hear about it :)

--
 
 
 

Steve Ross

unread,
Sep 20, 2012, 6:59:21 PM9/20/12
to rubym...@googlegroups.com
My mistake. Note to self: read first, write second :)

Sent from my iPhone
--
 
 
 
Reply all
Reply to author
Forward
0 new messages