0

I have an iOS app which downloads/parses strings from a JSON file. I need to store these strings in ONE NSArray. But every time I try I get the error:

expected method to write array element not found on object of type 'nsarray *'

All I am doing is assigning these strings to the array in a for loop.... And yet it won't work. It is baffling me why... I have assigned strings and variables to an array in C and C++.... Surely Objective-C supports this as well. What am I doing wrong?

Here is my simple for loop:

for (int loop = 0; loop <= [youtube_channel_id_tags count]; loop++) {

    self.getYTIcon = [[YTICONGET alloc] init];
    NSString *temp_url = [self.getYTIcon get_user_icon:youtube_channel_id_tags[_carousel.currentItemIndex]];
    youtube_user_icons[loop] = [temp_url description];
}

What am I doing wrong??

Thanks, Dan.

5
  • Try "NSArray" not "nsarray", Objective-C, C, and C++ are all case sensitive! Commented Mar 1, 2014 at 15:39
  • @trumpetlicks Yes I have defined my array as "NSArray". Commented Mar 1, 2014 at 15:41
  • BTW - your loop variable should be NSUInteger, not int. Commented Mar 1, 2014 at 15:42
  • @rmaddy Ah right, thanks. Its weird, the example in my Objective-C/Cocoa book say to use int.... Commented Mar 1, 2014 at 15:50
  • int will generally work but since NSArray count and all of the other index related methods to NSArray use NSUInteger, it is more correct. Commented Mar 1, 2014 at 15:52

2 Answers 2

3

youtube_user_icons needs to be a NSMutableArray so that you can change its contents and the line

youtube_user_icons[loop] = [temp_url description];

needs to be

[youtube_user_icons addObject:[temp_url description]];
Sign up to request clarification or add additional context in comments.

Comments

0

What is your youtube_user_iconstype? Should be NSMutableArray*, not nsarray *!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.