Re: Method Sees Populated Array As Empty
Re: Method Sees Populated Array As Empty
- Subject: Re: Method Sees Populated Array As Empty
- From: Mark Wales <email@hidden>
- Date: Sat, 5 Jul 2008 23:29:06 +0100
Is there any reason why a method would read an array as empty when
every other method has no problems accessing it?
I don't think so. More likely is that you are accessing an array
that is either empty or nil. It's impossible to tell without seeing
the code but my guess would be that you're not accessing the same
instance variable in -dataOfType: like you do in the other places
where it works as expected.
(Sorry, new to this list. Not sure if I should reply to you and CC:
the list or just reply to the list)
That's what I figured at first, but I copied the same NSLog(@"%@",
[self arrayOfReferences]) into every other method, so I don't see how
it could be accessing a different array. And if I check the array just
before and then just after it is not empty - so it can't be empty
because where would the data have gone to? It's very confusing, I can
see no reason why it would happen.
Here's some of the code:
Header
@interface MyDocument : NSDocument
{
....
....
NSMutableArray *arrayOfReferences;
}
Main
- (id)init
{
self = [super init];
if (self) {
arrayOfReferences = [[NSMutableArray alloc] init];
}
return self;
}
- (void)addEntryWithType:(NSString *)theType //longer in actual
version
{
Reference *reference = [[Reference alloc] initWithType:theType]; //
longer in actual version
[arrayOfReferences addObject:reference];
[textView refreshView];
}
- (IBAction)performSearch:(id)sender
{
NSLog(@"%@", [self arrayOfReferences]); // <== Works fine, shows
the array as populated before and after the dateOfType is done
[textView setSearchString:[searchField stringValue]]; // <== This
function uses the arrayOfReferences, so it must be populated
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
NSLog(@"%@", [self arrayOfReferences]); // <== Shows the array as
empty
if ( outError != NULL ) {
*outError = [NSError errorWithDomain:NSOSStatusErrorDomain
code:unimpErr userInfo:NULL];
}
// Create an NSData object
return [NSKeyedArchiver
archivedDataWithRootObject:arrayOfReferences]; <== doesn't do
anything, but that's because it thinks the array is empty
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden