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

pendal

macrumors newbie
Original poster
May 11, 2009
3
0
I am new to cocoa / objective-C .. and I am trying to make this work.

this is my function , that i thought would work.

all i want this function to do right now is return a text string

PHP:
-(char)actionComp{

 char message;
 message = @"The Files at location ",archSource, @"Will be compressed to ",archDest;

return message;

}

when i try to build and go i get the warning
"assignment makes integer from pointer without a cast."
on the message = line


the two variables archSource and archDest are listed as this in the .h file.

PHP:
char *archSource,*archDest;
}

@property(readwrite) archSource,archDest;

Can anyone help?

Thanks,
P
 
The construct @"My String" creates an NSString object. It is not a char. You need to alter your function to declare the correct return type (in this case (NSString *)). Even if @"My String" created a C-style string that would be a (char *) not a char.

Edit to add: you also need to alter you message variable. It needs to be NSString * not char. And I've no idea what you think the construct @"String",variable,@"string" is doing. It's certainly not doing string concatenation. I suggest you need to go right back to basics, read the documentation and learn the language before you try and write any code.
 
yeah i know .. i'm just trying to wrap my head around this language and can't seem to get anywhere.
 
I don't know that it will help much at this point, but:
Code:
-(NSString *)actionComp{
  return [NSString stringWithFormat:@"The Files at location %@ will be compressed to %@",archSource,archDest];
}

This is also assuming that archSource and archDest have been changed to NSString *, which makes more sense. Also, the NSString that is returned is autoreleased since actionComp doesn't contain the words new, copy, or alloc.

Here is what your original code is equivalent to:
Code:
-(char)actionComp{
  return (char)archDest;
}
archDest is a char *, so the value of the pointer will be cast down to char, hence the warning. There's about a 50/50 chance the char you end up with will be unprintable.

Here's the link to the NSString page:
http://developer.apple.com/document...lasses/NSString_Class/Reference/NSString.html

But you should probably start here:
http://developer.apple.com/document.../ObjectiveC/Introduction/introObjectiveC.html

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.