0

I am extremely new to Objective-C and iOS programming. The tutorial I am using has the following syntax for creating a NSString array representing the ranks of a deck of cards. My question is whether it is valid:

NSArray *rankStrings =@[@"?",@"A",@"2",@"3",...,@"10",@"J",@"Q",@"K"];

The reason for the question is that xCode is giving a red exclamation mark which says Expected expression. I don't want to mis-learn that ellipses are unacceptable. So I am asking here to know exactly why I am getting the error.

For comparison, python has range functions for creating lists. So maybe the ellipse here is comparable: I don't know. So can someone point out what's wrong with the declaration? Whether it is the ellipse, or how I am using them, or something else?

Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • 2
    Your book author was just too lazy to continue the array. You need to replace the ... with @"4", @"5", @"6", @"7", @"8", @"9" – Akaino Jun 30 '14 at 18:28

3 Answers3

2

Just replace

NSArray *rankStrings =@[@"?",@"A",@"2",@"3",...,@"10",@"J",@"Q",@"K"];

with

NSArray *rankStrings =@[@"?",@"A",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"J",@"Q",@"K"];

Objective-C can not continue the array for you on it's own. The book author was just a little too laze to continue so he inserted the ...

Akaino
  • 1,025
  • 6
  • 23
0

Can you please post more about your code?

and you are using

NSArray * @[objects ....]

and I am sure your Array

NSArray *rankStrings =@[@"?",@"A",@"2",@"3",...,@"10",@"J",@"Q",@"K"];

is right.

TianMing
  • 53
  • 7
  • It would be right if he wanted to create the array without the ellipsis. But as there are no automatic slicing operations in obj-C, it's wrong. (it's about the ... within the array) – Akaino Jun 30 '14 at 18:26
0

Something like the Python's advanced slicing operation using an ellipsis does not exist in Objective-C. Your code

NSArray *rankStrings = @[@"?",@"A",@"2",@"3",...,@"10",@"J",@"Q",@"K"];

is invalid.

Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382