How to move forward in building Core Data Applications: Beginner to Intermediate & Shuffle an NSArrayController
How to move forward in building Core Data Applications: Beginner to Intermediate & Shuffle an NSArrayController
- Subject: How to move forward in building Core Data Applications: Beginner to Intermediate & Shuffle an NSArrayController
- From: "Steven Harms" <email@hidden>
- Date: Mon, 27 Mar 2006 14:04:33 -0800
Hi,
I have 2 questions, one general, ane more specific.
First: How does one gain more competency in designing core data
applications. Most tutorials / documents / books provide a guide in
setting up the initial object model and building an application and
this is great, but where's the guide on what you do next? What if,
say, I wanted to start monkeying about with the NSArrayController that
contains my managed objects (like sorting it, or randomizing it
programmatically). In short, how do I get underneath the hood? Is
there a guide / tutorial / or is it just "read the docs from apple".
Second: As alluded to in point the first...I'm trying to randomly
sort an NSArray Controller
I did the blog example at cocoadevcenter
(http://cocoadevcentral.com/articles/000085.php).
I'm trying to figure out how to mod that example, to randomly shuffle
the "blog entries".
This would mean that after the NSArrayController which holds the
collection of post entities ("Post", as in a single post) is populated
with entities, I want to shuffle the array managed by this controller.
Now, each CD application has a delegate assigned to the File's Owner,
in this example it is called: BlogDemo_AppDelegate.
I thought that if I caught ApplicationDidLoad or AwakeFromNib in the
delegate I could print out some groovy data about what's in that
thing.
So, I did that with this snippet:
- (void)awakeFromNib
{
NSLog (@"XXX1Hi, I just awoke from nib with this controller: %@", posts);
NSLog (@"XXX1ArrangedObjeccts returns: %@", [posts arrangedObjects]);
}
Which made output like:
2006-03-26 20:33:19.112 BlogDemo[1483] XXX1Hi, I just awoke from nib
with this controller: <NSArrayController: 0x379470>[entity: Post,
number of selected objects: 0]
2006-03-26 20:33:19.112 BlogDemo[1483] XXX1ArrangedObjeccts returns: ()
AKA - nothing in there.
OK, so I then thought, what happens if I add a button with an action
to print out those same lines.
Sure enough this code:
-(IBAction)printStuff:(id)sender
{
NSLog (@"Hi, I just awoke from nib with this controller: %@", PostController);
NSLog (@"ArrangedObjeccts returns: %@", [PostController arrangedObjects]);
}
When triggered from a button-push produced this lovely output:
2006-03-26 20:33:20.740 BlogDemo[1483] ArrangedObjeccts returns: (
<NSManagedObject: 0x392f80> (entity: Post; id: 0x397480
<x-coredata://4BB32058-957B-467D-A1C1-D276CFAE2536/Post/p105> ; data:
{
author = nil;
body = "Body Text";
creationDate = nil;
title = "This is a new entry";
topic = nil;
}),
<snip>
You get the idea.
So, this leads me to conclude that I'm trying to find out about this
NSArrayController before its been loaded.
So here are the questions:
1. Is there any way to not do this in code (hee hee!) but with Core Data power?
2. Given that I must make code, I have the feeling that I found the
right file to do it in (the application's delegate). if awakefromnib:
and applicationdidload: are too early, where should I catch it?
Thanks,
Steven
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden