Extending the RubyMotionSamples Beer app with Nitron CoreData

134 views
Skip to first unread message

martins

unread,
May 9, 2013, 10:40:49 AM5/9/13
to rubym...@googlegroups.com
Hi,

I´m trying to extend the example Beer app to store it´s data using CoreData Models.
The original app displays Beer items on a map and in a list.

I´ve decided to replace Beer with Venue that I store using Nitron.


Here is the Venue model:

 1 class Venue < Nitron::Model
 2   # CoreData requires that every fetch be ordered somehow.
 3   def self.all
 4     order("due")
 5   end
 6 
 7   # We're using a text field to display a date when data binding.
 8   def due
 9     primitiveValueForKey("due").to_s
10   end
11 end


Unfortunately I´m not able to create new Venue items.

(main)> Venue
=> Venue
(main)> Venue.new
2013-05-09 16:32:59.051 Beers[7036:c07] app_delegate+core_data.rb:27:in `block in managedObjectModel': uninitialized constant Kernel::Event (NameError)
from app_delegate+core_data.rb:25:in `managedObjectModel'
from model.rb:25:in `entityDescription'
from model.rb:50:in `new:'
2013-05-09 16:32:59.124 Beers[7036:c07] model.rb:50:in `new:': NSInvalidArgumentException: An NSManagedObject of class 'Venue' must have a valid NSEntityDescription. (RuntimeError)
=> #<RuntimeError: NSInvalidArgumentException: An NSManagedObject of class 'Venue' must have a valid NSEntityDescription.>

Does anyone know how to add a valid NSEntityDescription to my Venue class?
Is Nitron the way to go when I want to add CoreData?

I´ve put the project at Github here: https://github.com/stabenfeldt/beer-nitron


Any tips or advice is highly appreciated! :-)



Cheers,
Martin Stabenfeldt

Matt Green

unread,
May 9, 2013, 10:54:25 AM5/9/13
to rubym...@googlegroups.com
I've been working on a successor to the CD stuff in Nitron for awhile now, but I'm not sure when it will be out (low on time as of late). It's a real problem, for sure.

Matt

wndxlori

unread,
May 9, 2013, 5:54:05 PM5/9/13
to rubym...@googlegroups.com
Hi Martin,

This seems to be a common issue, so I've started to put together a mini-ebook that will cover using CoreData in RubyMotion thoroughly.  Not ready for public viewing yet, but you are welcome to look at my experiment project.

I've taken Ray Wenderlich's CoreData tutorial posts (http://www.raywenderlich.com/934/core-data-on-ios-5-tutorial-getting-started), and the RubyMotion Location example (which is really basic CoreData), and merged them into a project with branches that illustrate:

CoreData models (multiple) with relationships:


Importing and pre-loading data into your CoreData Store:


And then adding an NSFetchedResultsController:


This isn't using any gems like Nitron, yet, because I wanted to understand how things work under the covers.  Hopefully you will find this helpful.

Regards, Lori

Martin Stabenfeldt

unread,
May 9, 2013, 9:09:32 PM5/9/13
to rubym...@googlegroups.com
This is gold, thanks! :-)

Cheers,
Martin

-- 
Martin Stabenfeldt
--
 
---
You received this message because you are subscribed to a topic in the Google Groups "RubyMotion - Ruby for iOS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubymotion/FlEnCIcSi4w/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to rubymotion+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

martins

unread,
May 12, 2013, 7:34:49 AM5/12/13
to rubym...@googlegroups.com
Hi,

I´ve started on merging your CoreData pattern into the Beers app.
Unfortunately it breaks when I do BeerStore.load:


(main)> BeerStore.load
{"name"=>"Chimay", "homepage"=>"http://en.wikipedia.org/wiki/Chimay_Brewery", "lat"=>"4.316667", "long"=>"50.016667"}
2013-05-12 13:28:18.897 Beers[19382:c07] beer_store.rb:69:in `initialize': Can't add persistent SQLite store: Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0x155f0aa0 {reason=Failed to create file; code = 2} (RuntimeError)
from beer_store.rb:4:in `shared'
from beer_store.rb:44:in `block in load'
from beer_store.rb:43:in `load'
=> #<RuntimeError: Can't add persistent SQLite store: Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed. (Cocoa error 512.)" UserInfo=0x155f0aa0 {reason=Failed to create file; code = 2}>

I created a directory named db and touched beers.sqlite, so the file should be accessible. Is that the correct way of initialise a db?
https://github.com/stabenfeldt/RubyMotionSamples/blob/master/ios/Beers/app/models/beer_store.rb#L69    


Cheers,
Martin

Lori M Olson

unread,
May 13, 2013, 8:06:30 PM5/13/13
to rubym...@googlegroups.com
I have not tried to explicitly create the store in a particular place (yet).  Following the tutorial, I have:

store_url = NSURL.fileURLWithPath(File.join(NSHomeDirectory(), 'Documents', 'banks.sqlite'))

And this file is just created for me, in the simulator.  I would just change that to 'beers.sqlite', and go from there.

I'm working on the next step in my research project, to load up a significant (240k records) amount of data, and then I'll have to figure out how to pull that file out of the simulator, and copy it into my project so it just starts up with all the data loaded.

Thomas Kadauke

unread,
May 13, 2013, 9:00:56 PM5/13/13
to rubym...@googlegroups.com
I used CHCSVParser in an Objective C app of mine back in the bad old days before RubyMotion ;)

I can't say anything about speed, since I did no benchmarks, but I thought the feature set was pretty nice. Seems there is also a pod for it.

--Thomas

Von meinem iPad gesendet
You received this message because you are subscribed to the Google Groups "RubyMotion - Ruby for iOS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubymotion+...@googlegroups.com.

Thomas Kadauke

unread,
May 13, 2013, 9:03:37 PM5/13/13
to rubym...@googlegroups.com
Sorry, that should have been a response to a different mail. Guess I shouldn't write emails when I'm half asleep :)

Von meinem iPad gesendet
Reply all
Reply to author
Forward
0 new messages