0

Sorry for this noob question, but how can i write this in 1 line?

NSInteger minuteInterval=5;
[countdownPicker setMinuteInterval:minuteInterval];

Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Manuel
  • 14,274
  • 6
  • 57
  • 130
  • 5
    Why must it be one line of code? – rmaddy Jan 31 '14 at 15:46
  • Because the first line seems superfluous to me, why to create an additional variable to pass a value to the setMinuteInterval method. – Manuel Jan 31 '14 at 16:00
  • There is nothing wrong with that. You could use a constant though instead. Your code will not be any less performant and assigning values to well named variables makes your code more readable (avoids ["magic" numbers](http://en.wikipedia.org/wiki/Magic_number_(programming))). In this case of course the meaning of the value is obvious from the method signature. – DrummerB Jan 31 '14 at 16:06

2 Answers2

2

This will work: [countdownPicker setMinuteInterval:5];

Greg
  • 25,317
  • 6
  • 53
  • 62
  • Why does this work if setMinuteInterval requires an NSInteger object according to Xcode? Isn't "5" an integer value rather than the required object of class NSInteger? – Manuel Jan 31 '14 at 15:52
  • 1
    An NSInteger isn't an Objective-C object, it's a long. From [Foundation Data Types Reference](https://developer.apple.com/library/ios/documentation/cocoa/reference/foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html): typedef long NSInteger; – jonmorgan Jan 31 '14 at 15:54
  • @ManuelTrezza The compiler will properly adjust the number literal to the needed type. – rmaddy Jan 31 '14 at 15:54
1
NSInteger minuteInterval=5; [countdownPicker setMinuteInterval:minuteInterval];
DrummerB
  • 39,814
  • 12
  • 105
  • 142