[MacRuby-devel] MacRuby Book discount

Morgan Schweers cyberfox at gmail.com
Thu Feb 3 20:52:41 PST 2011


Greetings,
Side note, in my litany of MacRuby awesomeness, I left out trivially easy
Grand Central Dispatch queues to do background downloading of HTML and
images!

I've sent a bit more details on this to Matt, but I wanted to share a
version with the list.

On Thu, Feb 3, 2011 at 5:35 PM, Matt Aimonetti <mattaimonetti at gmail.com>
 wrote:

> Thanks Morgan for the feedback.
>
> I appreciate your feedback on the CoreData chapter and I'm on the fence in
> regards to what I want to cover.
> I don't really aim for this book to be a Cocoa book, but a MacRuby book
> which is really hard since it's like writing a book about Objective-C
> without covering Cocoa in depth.
>
> If you can articulate a bit more what you thought was missing and how I can
> help, I'd be glad to try to cover these themes.
> The second part of the book is about real apps being built, I will probably
> cover some more advanced use cases.
>
> Thanks,
>
> - Matt
>

Sure, I'll take a shot at it...  I understand being on the fence; there's
depth there that can take entire (large!) books to cover. :)

For me, it's the advantage of being able to build desktop apps in Ruby makes
it worthwhile; Objective C is painfully verbose.  That said, I've been doing
a lot of Objective C recently, mainly building iPhone apps to scratch my own
itches, but the more I learn of the various Cocoa APIs, the better at
MacRuby programming I've been getting.

And therein lies the problem. MacRuby is powerful, but building good desktop
MacRuby applications still requires that you know Cocoa, and be able to
mentally translate between the two systems.  One good example is my figuring
out how to do drag-and-drop.  I had to dig through the NSDraggingDestination
protocol, and map that to MacRuby.  For example, most of the lines of
https://gist.github.com/810658 (drag and drop MacRuby example code!) have a
bunch of research and testing behind them that I couldn't have done without
at least a rudimentary understanding of Cocoa and Objective C.

For Core Data, I've only implemented it in my Cocoa Touch apps, but the
managedObjectContext seems to be a cross-cutting concern, needing to be
delivered to all the controllers that may need to pull data from the
database.  Then there's actually interacting with entities... For instance,
if you want to search for movies with the name 'Network', you'll need to do
some MacRuby equivalent to (adapted from some early, probably crappy, iPhone
code of mine):

     + (NSArray *)findByName:(NSString *)name fromContext:(
NSManagedObjectContext *)context {

    NSArray *fetchResults = nil;

    NSPredicate *predicate = nil;


    if (name != nil) {

      predicate = [NSPredicate predicateWithFormat:@"name = %@",name];

    }

    fetchResults = [super findFromContext:context withEntity:@"Movie"
andPredicate:predicate];

    return fetchResults;

  }

and that's a trivial example.  The more I dig into NSPredicate's, the more I
want an easier way to handle them in MacRuby.  Is there an easier way in
MacRuby world?  I don't know, and it's one of the things I was hoping to
find out. :)  What about mapping Entities to Ruby classes; is there any kind
of ORM-equivalent for Core Data?

Maybe I'm just complicating something that's really simple. Dealing with
Core Data in Objective C for the iPhone has left me nervous about all the
details of doing it in MacRuby. All of what I want to do is clearly doable
in Objective C under Cocoa, using predicates, contexts, and entities, but
it's not clear if there's a way to do it in MacRuby which isn't just a 1:1
translation of Objective C to MacRuby.

Hope that helps!

--  Morgan Schweers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20110203/96a4e82c/attachment-0001.html>


More information about the MacRuby-devel mailing list