miniplayground
miniplayground

Reputation: 301

Assignment from incompatible pointer type in my Objective-C code

Yesterday, I copied and compiled the code below and it was fine. But today when I compiled the code it gave me a warning and won't run the .exe. I'm new in Objective-C and I'm using GNUstep on window.

testString.m: In function 'main':
testString.m:5:13: warning: assignment from incompatible pointer type
** testString.m:5:13 it front of (=)

Here's the code.

//testString.m
#import <Foundation/Foundation.h>
int main (int argc,  const char * argv[])
{
NSString *testString = [[NSString alloc] init ];
testString = "Here's a test string in testString!";
NSLog(@"testString: %@", testString);

return 0;
}

Upvotes: 0

Views: 294

Answers (1)

Vladimir
Vladimir

Reputation: 170819

NSString literals must have @ symbol before them:

testString = @"Here's a test string in testString!";

One more problem with your code is that in 1st line you create an instance of NSString which you overwrite in the 2nd line - so it just leaks. Assign value to testString in its declaration directly:

NSString *testString = @"Here's a test string in testString!";

Upvotes: 6

Related Questions