[MacRuby-devel] Would a macruby-newbie List Be Worthwhile?

John Shea johnmacshea at gmail.com
Wed Dec 16 01:07:19 PST 2009


Hi Steve,

I agree with Ernie.

I am always happy to answer questions if I think the person is not rude, or asking me to write their entire app - and that is, so far, rare on this list.

Usually when I get it wrong other people pipe up ;-).

Some seemingly simple questions do often lead to a bug fix too.

Regarding your example, I not sure whether you did it or not, here is what I would do (i just tried this - so I know it works).

(Apropos Core Data: I have created a Core Data Document Template for XCode - it probably needs a bit of testing - but if anyone is interested let me know and i will post it somewhere)

Imagine you have created a (non document) app with out any CoreData infrastructure, then:

1. Create a new file in your project - standard ruby class, name it AppDelegate (or whatever you like).

2. Copy and paste the boiler plate code that you would get if you had an AppDelegate created from the Core Data template (eg from another project) to this file,  change the name of the xml file you are saving to (about line 50 in the current template). Also add/create a new mapping model (thats in the resource section when creating a new file), it will be used automatically.

or alternatively:

1&2. Create a new CoreData project from the template, and just drag these two files into the old project (in Xcode - not the finder).

3. in IB drag an nsobject into the ib project from the library, set the class to be the AppDelegate (or whatever you class is called that holds the boilerplate Core Data stuff above), also set the window iboutlet in the app delegate to the window (not actually sure if this is necessary - but the template comes like that). And make sure the application delegates to your app delegate (control drag from the application to your new app delegate).
4. Continue as you would normally with a core data app.

The second part, filling with data (presumably you will only need to do this once, because then the data can be saved with the app).
There are many ways to add data.

The easiest I reckon, is to add a method to the AppDelegate - called applicationDidFinishLaunching(notification) (delegated from the application singleton) and in that method you can do something like: 
new_student = NSEntityDescription.insertNewObjectForEntityForName("Student", inManagedObjectContext:self.managedObjectContext). 
Then set the attributes for that obj, eg student.name = "Bill".

This was at a high-ish level  - if there is something that you don't understand, feel free to ask - but ask in the next 7 hours, because I will be traveling and incommunicado for a couple of days.


Cheers,
John


On Dec 16, 2009, at 7:37 , steve ross wrote:

> Thanks for your feedback...
> 
> On Dec 15, 2009, at 4:19 PM, Ernest N. Prabhakar, Ph.D. wrote:
>> 
>> Hi "S",
> 
> Point taken :)
> 
>>> Would a newbie list be worth creating?
>> 
>> I would encourage you to just go ahead and ask on this list, for several reasons:
>> 
>> a) The people who would answer are here, so they may as well answer
> 
> That's what someone says every time somebody else suggests forking a list. I hope it's the right answer because a lot of my questions would be off topic both on this list and the Cocoa Developers list.
> 
>> b) It could be a bug, in which case it belongs here
> 
> Yeah, but at this point, I think many of us can tell when it's our own fault :)
> 
>> c) It helps us understand usage issues, which may inform features and documentation
> 
> Again, point taken.
> 
>> The more interesting question to me is when do we create a macruby-users list for those using the "stable" version -- or move development OF macruby to a "macruby-core"?
>> 
>> I guess it depends on when MacRuby is stable enough and popular enough.  At any rate, it isn't yet.
>> 
>> -enp
>> 
>> 
>> On Dec 15, 2009, at 11:21 AM, s.ross wrote:
>> 
>>> There are a number of questions I know I have coming from a Ruby/Rails and not a Cocoa background. These questions can be difficult to answer in the context of Objective-C (and heck, Ruby makes a lot of the Objective-C syntactic vinegar just go away). They are also not specifically about MacRuby, but rather about how it interacts with the framework.
>>> 
>>> Because MacRuby can open up Cocoa to developers who really didn't want to mess around with [[obj alloc] init] and all that stuff. Many of you on this list did go through that learning experience but have already answered these same questions before in a different context but shouldn't be imposed upon to answer them again. Would a newbie list be worth creating? I find myself coming up with seemingly stupid questions that I simply don't want to trouble the list with but that take hours to dig out of the documentation. That would be the proposed purpose. Post some code, expected results, and what's actually happening.
>>> 
>>> Maybe an example: I want a single pane Core Data application but I forgot to select the template that creates an appDelegate. How do I get a managedObject context and how do I add some seed data to that collection once it's bound to an NSTableView. See? Complicated n00b question that requires IB steps and Ruby steps. Takes quite a bit of trekking around in the documentation to figure out. But someone who's walked the same path before could answer it right away.
>>> 
>>> Comments?
>>> _______________________________________________
>>> MacRuby-devel mailing list
>>> MacRuby-devel at lists.macosforge.org
>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>> 
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
> 
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel



More information about the MacRuby-devel mailing list