Re: NSDictionary dictionaryWithContentsOfFile in Carbon app
Re: NSDictionary dictionaryWithContentsOfFile in Carbon app
- Subject: Re: NSDictionary dictionaryWithContentsOfFile in Carbon app
- From: "Roni Music" <email@hidden>
- Date: Mon, 9 Oct 2006 12:16:20 +0200
----- Original Message -----
From: "Uli Kusterer" <email@hidden>
To: "Roni Music" <email@hidden>
Cc: <email@hidden>
Sent: Sunday, October 08, 2006 11:12 PM
Subject: Re: NSDictionary dictionaryWithContentsOfFile in Carbon app
Am 08.10.2006 um 20:51 schrieb Roni Music:
Would this modified example be correct?
In principle, yes.
Good!
But you need to get your variable names right: You sometimes wrote
anArray and aDictionary where it should be m_anArray and m_aDictionary
:-p
Yes, this wouldn't compile and actually never tried
just a dummy example to explain questions,
foo:: foo()
{
m_aDictionary = 0;
m_anArray = 0;
}
Just a small style thing: It's a pointer, not an int, so you *should*
really be assigning this NULL instead of zero to make that clear.
Comming from the Windows world, I usually use Hungarian notation to make
clear what kind of type variables are
int *m_pToSomething = 0;
but it's of coure allways good to be as clear as possible
again thanks for responding!
Rolf
Also, in ObjC the convention is to use the constant "nil" to mean "an
uninitialized object" (it's basically the same as NULL, but I use the
three to help me distinguish in code: 0 is an int, 0.0 a float, NULL a
classic pointer or C++ object and nil an ObjC object.
// this function will be called several times
// creates the dictonary and array objects
void foo::bar()
{
CAutoRelease autoReleaseMe;
.....
[m_aDictionary release]; // OK to release even if it's NULL? (which it
is the first time being called)
aDictionary = [NSDictionary dictionaryWithContentsOfFile:[aString
stringByExpandingTildeInPath]];
[m_aDictionary retain];
[m_anArray release];
anArray = [aDictionary objectForKey: @"aKey"];
[m_anArray retain];
......
//now use the array
}
Yes, if you look at Apple's Objective C book <http://
developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/ ObjC.pdf>
on page 42, you'll see that you can safely send messages to NIL as long
as the method's return type is one of a select few. Since the return type
of retain is void, that's OK, too. (Though I'm kinda surprised the docs
don't mention "void" as being OK, I should probably file a bug about
that).
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
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