• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Objects return nil
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objects return nil


  • Subject: Re: Objects return nil
  • From: Stefan Schüßler <email@hidden>
  • Date: Thu, 7 Aug 2003 19:10:36 +0200

You should retain the value-object in order to keep it after the NSDictionary is autoreleased at the end of your init method:

tokenLines = [[lineDict objectForKey:key] retain];

Stefan

Am Donnerstag, 07.08.03 um 15:09 Uhr schrieb Michael Hanna:

This has been stumping me so I'm putting it to the list..

I have a Lines object that reads in an NSArray from a plist:

::: FROM Lines.m :::

@implementation Lines

- (id)init
{
self = [super init];
linesPath = [[NSBundle mainBundle] pathForResource:@"lines" ofType:@"plist"];
lineDict = [NSDictionary dictionaryWithContentsOfFile: linesPath];
key = @"lines"; // key to get lineArray from the NSDictionary
tokenString = @"%s"; // the 12 tokens to be replaced within the while-loop
tokenLines = [lineDict objectForKey:key];
NSLog(@"tokenLines: %@", tokenLines); // p/o the contents fine

return self;
}

[...]

- (NSArray *)tokenLines
{
return tokenLines;
}

::: END :::



however, the caller, CSController.m, gets returned an array with a count of 0 and nil when I try to get another data member, tokString:



::: FROM CSController.m :::

NSMutableArray *lineArray;
NSString *tokString;

[...]

lineArray = [[NSMutableArray alloc] initWithArray:[lines tokenLines]];
NSLog(@"got here 1.5");
NSLog(@"lineArray: %@", lineArray); // prints-out an empty array
tokString = [[NSString alloc] initWithString:[lines token]]; // nil error message

[...]

::: END :::


::: OUTPUT :::

2003-08-06 20:30:39.010 Country Song[6754] tokenLines: <CFArray 0x1d7c60 [0xa01303fc]>{type = mutable-small, count = 8, values = (
0 : <CFString 0x1d7c80 [0xa01303fc]>{contents = "I met [.....]

2003-08-06 20:37:03.078 Country Song[6754] lineArray: <CFArray 0xdf9dd0 [0xa01303fc]>{type = mutable-small, count = 0, values = (
)}
2003-08-06 20:37:03.091 Country Song[6754] [NSPlaceholderString initWithString:]: nil string (or other) argument


Why do my objects return nothing? Also, the NSArray returned is retrieved as an NSMutableArray. Is explicit casting necessary?

Michael
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Objects return nil (From: Michael Hanna <email@hidden>)

  • Prev by Date: display windows
  • Next by Date: Re: String Encoding Detection (Revisited)
  • Previous by thread: Objects return nil
  • Next by thread: Re: Objects return nil
  • Index(es):
    • Date
    • Thread