[MacRuby-devel] Need to Write Core Data Accessors in MacRuby?

Robert Lowe rob at iblargz.com
Tue Jun 28 09:02:51 PDT 2011


On 2011-06-28, at 11:55 AM, Shannon Love wrote:

> I'm not to the point of wiring up the UI yet. I will employ bindings when I do so but at the moment I am creating a complex data model using NSManagedObject subclasses with lots of customized behaviors. I do this all the time in Objective-c but I am uncertain how to go about doing so in MacRuby. 
> 
>  The @dynamic processor in Objective-C 2.0 autogenerates attribute and relationship accessors except for the to-many relationship convenience methods but obviously MacRuby has no such capability. I don't think the `attr_accessor ` in ruby will generate the proper core data accessors. 
> 
> I suppose my real question is: Do we have to write all the accessors like we used to do in the early days of Core Data in Objective-s 1.0 or is there some functionality in ruby or MacRuby that obviates the need to do so? 

I believe as it's not compiled, attr_accessor just allows read/write.

It might be easier to implement the models in objective+c to take advantage of the processors. 

I'm still new to macruby,

Hope it helps,
 - Rob

> 
> Thanks,
> Shannon
> 
> 
> On Jun 27, 2011, at 5:55 PM, Matt Aimonetti wrote:
> 
>> Hey Shannon,
>> 
>> I'm not sure I fully understand, but you should be able to just set the accessor and do the binding via Xcode as shown here: http://ofps.oreilly.com/titles/9781449380373/_core_data.html
>> Let me know if that doesn't answer your question.
>> 
>> - Matt
>> 
>> On Mon, Jun 27, 2011 at 3:45 PM, Shannon Love <techzen at me.com> wrote:
>> Howdy,
>> 
>> I've Core Data a lot in Objective-c and now I am trying to use it in MacRuby. It occurs to me that I might need to create the to-many relationship accessors just like you have to do in Objective-C. 
>> 
>> To clarify: Suppose I have a data model that models a file structure and which looks like this:
>> 
>> Folder{
>>   name:string
>>   parent<<-->Folder.subFolders
>>   subFolders<-->>Folder.parent
>>   files<-->>File.folder
>> }
>> File{
>>   name:string
>>   folder<<-->Folder.file
>> }
>> 
>> In Objective-C, I would normally have methods in the `Folder` class that would look like:
>> 
>> addSubFoldersObject:
>> removeSubFoldersObject:
>> addSubFoldersObjects:
>> removeSubFoldersObjects:
>> 
>> The methods themselves would use look something like:
>> 
>> - (void)addSubFoldersObject:(FetchedPropertyExtractor *)value {    
>>     NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
>>     [self willChangeValueForKey:@"SubFolders" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
>>     [[self primitiveValueForKey:@"SubFolders"] addObject:value];
>>     [self didChangeValueForKey:@"SubFolders" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
>>     [changedObjects release];
>> }
>> 
>> Do you have to do the same thing in MacRuby or will the normal ruby set operations suffice?
>> 
>> Thanks,
>> Shannon Love a.k.a TechZen
>> 
>> 
>> 
>> _______________________________________________
>> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20110628/81cfa69c/attachment.html>


More information about the MacRuby-devel mailing list