Doug Smith
Doug Smith

Reputation: 29326

Why is Xcode "expecting an identifier" here?

destination.wordsPerMinute = [NSNumber numberWithInt:(int)[self.wpmSlider.value]];

I'm accessing the view controller I'm segueing to's wordsPerMinute property (an NSNumber) and setting it equal to an NSNumber converted from an int, which was a float cast as an int.

Upvotes: 1

Views: 101

Answers (4)

redent84
redent84

Reputation: 19249

With new compilers (XCode 4.5+):

destination.wordsPerMinute = @((int)self.wpmSlider.value);

Otherwise:

destination.wordsPerMinute = [NSNumber numberWithInt:self.wpmSlider.value];

Upvotes: 1

Anoop Vaidya
Anoop Vaidya

Reputation: 46563

You can use (in new compilers)

destination.wordsPerMinute = @(self.wpmSlider.value);// [NSNumber numberWithInt:(int)[self.wpmSlider.value]];

If you want to convert it into integer value then :

destination.wordsPerMinute = @((int)self.wpmSlider.value);

Upvotes: 1

Martin Ullrich
Martin Ullrich

Reputation: 100751

Remove the [] brackets around self.wpmSlider.value
The compiler expects a method name as identifier here (like numberWIthInt: in the outer method call)

Upvotes: 1

Richard Brown
Richard Brown

Reputation: 11444

You don't need the brackets around [self.wpmSlider.value].

Or use

[self.wpmSlider value]

Upvotes: 4

Related Questions