Showing posts with label coredata. Show all posts
Showing posts with label coredata. Show all posts

Saturday, 15 September 2007

Retain Release Revolt - Bring Me Leopard Objective c2.0

So I ripped out the Ruby and got my new project running and have been writing the methods that were done in Rubycocoa

The only trouble is.... You do an ebay search and it produces the right results. Try again and it produces nothing. Open a web address, it works. Try again it crashes.

I now have to wrap my head around memory management properly. I understand what I'm supposed to be doing but I need to go into my code and start working out where to retain/release/autorelease. Having come back from Ruby, I find myself longing for Objective C2.0.

The bit that I need to take on board is where objects are retained automatically by adding to collections and when to release the collections and create a fresh object.

It's not rocket science, but I'd prefer not to have to do that kind of thing.

Garbage Collection I <3 you.

I went to an Apple Leopard Dev event last Winter and the stuff on Objc2.0 was cool, I can't believe I'm under NDA. actually I'm not because they forgot to ask anyone to sign it, but everything I know is already on Apple's website anyway.

October can't come soon enough.

Things I'd like to see in Leopard for dev's
Easier syntax for arrays and dictionaries.
Yes its not that bad now, but Ruby is so much clearer ( like most languages )
howabout
NSArray* myarray = @( obj1, obj2, obj3 )
or
NSDictionary *mydict = @{ obj1, @"obj1", obj2, @"obj2 }

That would be nice and fast

  • CoreData connecting easily to mysql

  • Set/Get creation syntax.

  • Set/Get that works with keypaths. Then I wouldnt need to type


    [ myobject valueForKeyPath:@"path.path" ], instead I could use [ myobject.path.path ]




Stuff that we know is coming from Apple's website


  • Easier array iterators. Thats welcome. I love Rubys Array.each{| element | code }

  • Garbage Collection - yay

  • Easier accessors - yourobject.value really those []'s get a bit of a mouthful sometimes

  • Better error hiliting in xcode, yay. I love textmate, wish xcode was a bit more like that.

  • Core animation I want to do a spinner, praps this will be the best way




Update, how easy was a spinner, duh!

Thursday, 13 September 2007

import xml into NSDictionary

I've spent the last few days fiddling on an NSXMLNode category that creates a method called

xmlToDictionary

+(NSDictionary) xmlToDictionary:node


You just give it an xml node and it returns a dictionary that you can query like this...


xmlDictionary = [ XMLNode xmlToDictionary:rootNode ];


value = [ xmlDictionary valueForKeyPath:@"SearchResultArray.SearchResultItem" ]



I thought when the documentation said that NSXMLNode was kvc compliant that it would do this, but it didnt mean that it meant stuff like [ rootNode valueForKey:@"children" ] which is obvious really.

I also thought there must be a way to do the above, and there still might be, but I didnt find it.

I looked at using XPath and that is a solution. I also looked at applying an XSLT sheet against the XMLDoc and using that to convert to plist format and then reading that into NSDictionary. But I dont know XSLT and thought this was an interesting method to write.

I also wrote another category method nodeForPath:(NSString*)path that does a similar job but simply parses a path like "SearchResultItemArray.SearchResultItem" and produces the value on the fly. Actually its probably better to do it like that.

I'm experimenting with native NSXMLNode methods and my own ones to see which is easier and clearer to read.

Reuse/import coredata model

So I've finished learning how to interrogate ebay using cocoa/objc and can now read the data without having to resort to ruby

So now I have my tools on how to get the data and can stop using Ruby for that side, which I wasnt too bothered about except the current rubycocoa version can't use webkit as I have installed Safari 3 and its not compatible. This is why I've been changing to writing a pure cocoa app, that and wanting to know how things work..

So now I have my cocoa ebayapi, and my original rubycocoa app, and I was trying to figure out how to take the original main menu.nib and also the original xcode coredata model, and add them to a new project. I couldnt seem to find any direct info on that, although I do get the documentation, I just wasnt sure what steps I needed.

This is what I came up with
  • 1. Create new coredata project

  • 2. Copy mainmenu.nib over the new projects mainmenu.nib

  • 3. Add File to Project and select the previous projects xcode datamodel (xcdatamodel )

  • 4. For testing, copy the xml data file from ~/Library/ApplicationSupport/oldproject/oldproject.xml to samepath/newproject/oldproject.xml

  • 5. alter project_Appdelegate.m to use the new(old) xml filename, not the default one for the new project name

  • 6. Go into the mainmenu.nib in interface builder and pull in the header file from xcode for the appdelegate, and delete the old app delegate.

  • 7. reconnect files owner to new app delegate

  • 8. change the arraycontrollers to use the new managed object context from teh app delegatge ( in their bindings )


That seems to work at the moment

I wonder if theres anything I'm missing.

And now I remember how much recursion makes my head spin.