Search posterous

Search all posts and users. Type a name, type a favorite song title, whatever! See what comes up.
  

More posterous blogs











More recommended blogs »

Here are posterous posts filed under cocoa...

dealnay says...

SAVE $5.7 - Ghirardelli Hot Chocolate Mix, Chocolate Hazelnut, 16-Ounce Cans (Pack of 4) $19.02

SAVE $5.7 - Ghirardelli Hot Chocolate Mix, Chocolate Hazelnut, 16-Ounce Cans (Pack of 4) $19.02Price: $24.72 Now: $19.02 You save: $5.7

The luxuriously deep flavor of Ghirardelli Premium Chocolate Hazelnut Hot Cocoa creates the intense, lingering chocolate experience cherished by tru e cocoa lovers. More info »

Shop Now »»

Permalink: dealnay.com/153897

More deals on Cocoa Food & Drink Grocery

Last updated: November 25, 2009, 12:15 am

Filed under: Cocoa

Justin says...

I've been tossing a few ideas around for a while now. Most of them weren't very good. Then something happened; I had a problem. A problem I've had many (many) times. A problem with a small, but distinct audience. A problem without an existing solution!

"What is it?" you ask?

Unfortunately, this is the part where I tell you I can't reveal exactly what that problem is. I can't tell you because it would keep me up at night waiting for someone who actually knows what they're doing to knock out this application in a week and leave me with nothing to do but cast disparaging remarks at them on Twitter. Suffice it to say, it's niche.

"Well, from what you've told us so far, it sounds great!" you say, and I thank you for that.

So now I've got this idea, like I said, and it's pretty good one. But there's a catch, you see. I don't really know Objective C, or Cocoa, or Cocoa Touch if you want to be a jerk about it. I have little experience writing desktop applications and I'm honestly still a little uncomfortable around words like "retain" and "release". While I'm a pretty quick study, there's something to be said for hitting the ground running.

So this gives me a new idea! Maybe if force myself to document my experience writing this application it will help motivate me. Maybe, it will help someone else and I'll earn some brownie points with the Universe. Maybe if I actually finish this thing someone might stumble across this blog and feel so sorry for me that they buy the application out of pity! That's a win-win-win by my reckoning (it's also a lot of "maybes").

So what's next? I'm not entirely sure. I'll probably try to summarize what I've done so far to prepare myself (you know, montage style). I might also get distracted and lose interest. I don't know, and that's what makes this fun.

Filed under: cocoa

Dubber says...

Filed under: Cocoa

Archimage says...

So in the last two posts I dealt with setting up CoreData within an existing project, binding the data (NSManagedObjects to a control) and actually getting the objects to save to a file (store).  In this last entry, I'll deal with pulling data from the file in order to display it in the control.   This code assumes you have an NSManagedContext I'm calling newContext.

NSError **theError = nil;  // set up an error code

// We need to use an NSEntityDescription that the docs describe as being an abstract form of NSManagedObject. (It's like "id" is to classes.)  
// When we create an NSEntityDescription we need to map it (think cast it) to the entity in our data model we want to read within our context.
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Recent" inManagedObjectContext:newContext];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];  // Create a CoreData fetch request (NSFetchRequest)
[request setEntity:entityDescription];  // tell the fetch request what type of entity we want to fetch (using our NSEntityDescription)

 

 

 


// Here we need to specify our NSPredicate (think SQL SELECT predicate) to specify the subset of objects to read from our store.
// The bad news is that CoreData predicates don't use SQL syntax, which is a shame.  They use their own special syntax which makes learning a bit more problematic
// and difficult.
// I am keeping things simple here and am going to assume if I don't specify a predicate CoreData will do the sensible thing and return all objects.
// (I am just guessing here, since I didn't feel like wading thru the NSPredicate Programming Manual.)
// NSPredicate *predicate = [NSPredicate predicateWithFormat:...];
// [request setPredicate:predicate];

 

 

 


// Next, we create an NSSortDescriptor which is used to sort the object during the fetch (think an SQL ORDER BY clause.)

// Specify the property name within the entity we want to sort by (I'm using gitName) and the sort order.
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor allocinitWithKey:@"gitName" ascending:YES];
[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];  // tell the NSFetchRequest to use the sort descriptor
[sortDescriptor release]; // clean up

 

 

 


NSArray *array = [newContext executeFetchRequest:request error:theError]; // create an array with the results of executing the fetch request on our context.
if (array != nil)
{
// move the results to our array of objects which are bound to our control.
}
else
{
// Deal with error...
}
[array release];

That's it--it works!

So, what have I learned?  Once things are set up CoreData isn't bad or overly difficult to use in this simplest of approaches. The code I've presented is pretty brute-force, but it works.  The complexity as I see it comes in learning how to manage the various layers of the graph:  the persistent store, the context, the managed objects themselves, and probably the hardest layer, the predicates.  There are some analogs to what and how SQL works, but its not as simple as SQL.  SQL is declarative and purely syntax driven.  CoreData is obviously object-oriented, but its more complex than an ORM (Object-Relational Mapping) tool such as hibernate.  

Am I going to keep using CoreData?  Yes, mainly because I got the basics working, it gives me a level of confidence, and I know I can pick up the more complex options as I need them bit by bit, and I personally have no need to learn all of CoreData at once.  

Is CoreData more cumbersome and complex than it has to be? Probably.  

Filed under: Cocoa

Archimage says...

Continuing on my quick CoreData excursion, here is what I figured out and learned today  regarding actually getting your NSManagedObjects to save to a real file.   This assumes the previous post's code.

Saving your objects to the file/store is pretty straight forward.  Again, I'm just trying to get basic functionality working.   Once I have that done I can expand on my knowledge and what I try to code after I understand what is going on. 

Saving is pretty straight forward once you have the setup code done.  In the previous entry's code example, there is a comment you need to remove and implement:

//- (NSPersistentStore *)addPersistentStoreWithType:(NSString *)storeType configuration:nil URL:(NSURL *)storeURL options:(NSDictionary *)options error:(NSError **)error     // this is what you use to set up the database type, etc.  In this snippet I don't worry about it because I just want it to compile and display something.

This is my brute force code:
NSError *error;  

// Build an NSURL to our physical database file.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *folder = @"~/Library/Application Support/Tiny±Git/";
folder = [folder stringByExpandingTildeInPath];
if ([fileManager fileExistsAtPath: folder] == NO)
{
[fileManager createDirectoryAtPath:folder withIntermediateDirectories:NO attributes:nil error:error];
}

    

NSURL *fileURL  = [NSURL fileURLWithPath: [folder stringByAppendingPathComponent: @"TinyGit.sqlite"]];

// Now tell our NSPersistanceStoreCoordinator the type of DB you want (I'm using SQLite, you can also use XML, etc.) 
// Pass in our fileURL NSURL which is where the database will be strored. 
// There are also configurations, and options, but we can ignore this--I'll worry about those once I get this working.
[psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:fileURL options:nil error:error];

Once you have the store coordinator set up this way, then all you have to do to store your NSManagedObject(s) is call:

[newContext save:error];

after you have created them and added them to the NSManagedObjectContext.  The interesting thing here is that the the save: actually forces all the objects within the context to be saved all at once.  It's all or nothing.  So make sure you only add the objects to the context that you want to end up in the database.

Just to verify that this actually did work, I went to my Application Support folder and sure enough there was a new Tiny±Git folder and within it a new file TinyGit.sqlite.  Just to see what got stored (if anything) I opened it up with SQLiteManager:

Compare this with the actual data model:

So, it looks like CoreData builds lots of infrastructure.  Just to see what data got stored I drilled into the data:

Well at least the data that I specified for my simple example in the previous post got saved properly, but there sure is a lot of extraneous stuff going on under the covers.

What do I conclude from all this?  I honestly am not sure. I'm feeling a bit more confident after seeing how relatively easy it is (although limiting) to save a context.  I'll have to see what it's like to actually retrieve/fetch data using CoreData.

Filed under: Cocoa

thefabawards says...

Cadbury and Ghana celebrate Fairtrade pact

If you think the drumming gorilla or dancing-eyebrows kids got big heads from starring in Cadbury ads, check out the oversized star of "Zingolo," this new Cadbury video, shot in Ghana. The song is the first single off an album from the firm's Glass and a Half Full Productions celebrating African music and culture, while touting the U.K. confectioner's switch to Fairtrade cocoa. (Cadbury will pay a guaranteed minimum price for Ghanaian cocoa under a £45 million initiative over 10 years.) The song is infectious, and we'll assume Cadbury doesn't really use exploding, psychedelic cocoa beans in its chocolate bars (though it would explain why I feel high after a few bites). Best of all, there's no Phil Collins on the soundtrack.

—Posted by David Gianatasio

Filed under: Cocoa

chak says...

Here is the language specification for blocks (that is lambda abstractions) for C, Objective-C & C++ as implemented in the Clang compiler and used in Mac OS X 10.6 (Snow Leopard):

   http://clang.llvm.org/docs/BlockLanguageSpec.txt

Filed under: cocoa

mickes says...

Filed under: cocoa

jsmp says...

Here are some of the resources I find interesting, this is not meant to be a extended version but just a quick post to play with posterous.

As an Objective-C/Cocoa Developer:

As an designer/artist
As for electronics

Have fun.

Filed under: cocoa

obleo says...

A Stanford computer science class is available to the general public free online. The full 10 week course includes videos and pdf's. Online viewers of the Stanford course will see the same lectures as the on-campus students, but will not receive credit for the course.

23 videos around a hour each and 17 pdf docs.

see it, download it (with iTunes) @ http://deimos3.apple.com/WebObjects/Core.woa/Browse/itunes.stanford.edu.2024353965.02024353968

Filed under: cocoa