Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mysterytramp

macrumors 65816
Original poster
Jul 17, 2008
1,334
4
Maryland
I'm trying to compile the Amazon-XML example from MacTech. Here's the article, here's the source.

The program compiles but the run log provides cryptic messages which seem to show there's a problem in the nib file.

What puzzles me is that the compiler offers a "warning"

It's on this line of code:

NSXMLElement *detailsNode = [rootNode childNamed:mad:"Details"];

And the warning says, "NSXMLElement may not accept childNamed message"

First, it seems so ... indecisive ... to say NSXMLElement "may" not accept a message. Shouldn't the compiler know? It seems to add a whole new level of error handling if you need to worry about what may or may not be acceptable.

Second, sometimes the compiler gives that message and sometimes the compiler says "warning: initialization from distinct Objective-C type" Getting separate error messages for the same line seems awfully weird. If I were more of a sexist I'd think XCode were a woman. (Of course, now that I'm trying to document it, XCode offers only the initialization error.)

I never worked with a compiler that gave "warnings" just errors. Is this kind of behavior common?

mt

Running 10.4.11, mac mini, XCode 2.3
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
Since Objective-C makes calls via message passing instead of direct invocation, and classes can be created/modified at runtime, the compiler cannot know for sure that an instance won't respond to a particular message at runtime. It is very likely that it will not if you aren't actively manipulating class definitions in your program, but this is why the compiler warns you. Most of the time this will result in a runtime error, and you should correct the problem.

http://www.mactech.com/articles/mactech/Vol.21/21.06/XMLParser/

This article has a category on NSXMLNode that will add the function you seem to be wanting to use. From what I can tell from the NSXMLElement and NSXMLNode references, the method childNamed: is not part of the API.

I have rarely worked with a compiler that did not give warnings. Most of the time the compiler tries to gently nudge you into fixing things that look like problems. For example, in C you can assign an int to a pointer without an explicit cast. The compiler will warn you, but this isn't an error. It's likely to develop into an error if you move to a system where sizeof(void *) is not equal to sizeof(int), but you didn't make any syntax errors, so the compiler just warns you that you might be doing something wrong.

-Lee

Edit:
You shouldn't take my word for the dynamism mentioned, i suppose:
A full example:
http://theocacao.com/document.page/327
Apple Runtime reference:
http://developer.apple.com/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html
See class_addMethod, specifically.
 

mysterytramp

macrumors 65816
Original poster
Jul 17, 2008
1,334
4
Maryland
Thanks lee

The bulk of my "real" programming was in Pascal, which if memory serves was a "strong" typed language (I forget the exact term). I can vaguely remember the debate, way back then, on why Pascal nuts thought the language superior to the upstart C -- one reason was that variables were specifically cast, you couldn't make the mistake of treating a char like an int because the language wouldn't let you.

In that environment, it's probably "easier" for the compiler. A mistake is a mistake, not what it "thinks" is a mistake.

I miss Pascal. There's something comforting about knowing a function has a begin and an end.

mt
 

mysterytramp

macrumors 65816
Original poster
Jul 17, 2008
1,334
4
Maryland
Thanks lee

The bulk of my "real" programming was in Pascal, which if memory serves was a "strong" typed language (I forget the exact term). I can vaguely remember the debate, way back then, on why Pascal nuts thought the language superior to the upstart C -- one reason was that variables were specifically cast, you couldn't make the mistake of treating a char like an int because the language wouldn't let you.

In that environment, it's probably "easier" for the compiler. A mistake is a mistake, not what it "thinks" is a mistake.

I miss Pascal. There's something comforting about knowing a function has a begin(ning) and an end.

mt
 

JonnyThunder

macrumors member
Aug 16, 2008
67
0
Is it not possible that this method has been added using categories? I'm asking out loud because I'm only a third of the way through my Obj-C book, but remember reading it in the apple documentation. You can add methods to classes using categories without knowing the workings of the original class?

Maybe there is a file missing or not included?
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
Just check the 'treat warnings as errors' checkbox and you'll get all the strong checking you want unless you specifically turn it off by typing the variable as id. Or just learn to treat warnings as important things.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.