Re: Struggling with basics of Objective C
Re: Struggling with basics of Objective C
- Subject: Re: Struggling with basics of Objective C
- From: James Spencer <email@hidden>
- Date: Sun, 6 Mar 2005 16:31:06 -0600
On Mar 6, 2005, at 3:15 PM, John Hopkins wrote:
Guys thanx, that explains why project builder didn't like what I was trying to do. It does seem to be an area of cocoa that I have come across so far that seems to complicate an otherwise simple thing. But then again I am a noob and was trying to add two classes together!!!
On 6 Mar 2005, at 21:06, Michael Hanna wrote:
if num1, num2 are int, then
num1 = [inputArray objectAtIndex:0];
num2 = [inputArray objectAtIndex:1];
would mean that you're trying to store the addresses of those objects into the ints. They're NSNumber objects, so why not do
num1 = [[inputArray objectAtIndex:0] intValue];
num2 = [[inputArray objectAtIndex:1] intValue];
After coding a couple of apps in Cocoa, I'm starting to wonder if NSNumber objects are any use at all actually.
Michael
On 6-Mar-05, at 3:47 PM, John Hopkins wrote:
Hi Im new to all this and have had a few successes in making my programming do what I want it to do. Yet I am struggling with some of the basic stuff. ANSI C for example I can add two integers together quite simply. However in OBjC when I recall two integers from an array and assign them to a variable I keep getting the following warning message: assignment makes pointer from integer without a cast. What does it mean? How do I make it right? Please forgive my dimness I'm quite new to all this.
inputArray = [[NSMutableArray alloc] initWithCapacity:7];
x = [[sender selectedCell] tag];
[inputArray insertObject:[NSNumber numberWithInt:x] atIndex:0];
num1 = [inputArray objectAtIndex:0];
num2 = [inputArray objectAtIndex:1];
answer = num1 + num2;
NSNumbers exist, as much as for any other reason, because the collection classes such as NSArray and NSDictionary can only store objects, not C primitives. But keep in mind that if all you need is a standard C array of ints, then use one. Granted that array won't have some of the neat features of an NSArray but you also won't have to jump through the hoops of extracting the values to be able to do math on them either.
James P. Spencer
Rochester, MN
email@hidden
"Badges?? We don't need no stinkin badges!"
_______________________________________________
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