Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
December 17, 2018, 12:45:09 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
Author Topic: What's wrong with this code snippet?  (Read 2534 times)
Posts: 14

« on: September 09, 2009, 09:18:43 AM »

I think this should work, but it doesn't.  I must be missing something very basic.

const NSString words[] = {@"Happy", @"Birthday"};
NSString *word;
word = @"Birthday";
word = words[1];   

At the last line, the compiler says "error: incompatible types in assignment."  But words[1] is @"Birthday".  So why is it OK to set word equal to @"Birthday" but not OK to set it equal to words[1]?
Global Moderator
Full Member
Posts: 212

« Reply #1 on: September 09, 2009, 10:37:06 AM »

Just as word is a pointer to an NSString object, words needs to be an array of pointers to NSString objects.
You forgot the *

const NSString *words[] = {@"Happy", @"Birthday"};

Sanity: Minds are like parachutes. Just because you've lost yours doesn't mean you can borrow mine.
Pages: [1]   Go Up
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 All rights reserved.