Primitivos y formatos en Objective-C
Los tipos de C viven junto a los objetos; BOOL responde YES o NO.
#import <Foundation/Foundation.h>
int main(void) {
@autoreleasepool {
// C primitives live alongside objects; BOOL is YES or NO.
NSInteger stock = 148;
double price = 24.99;
BOOL openSunday = NO;
// Format specifiers: %ld for NSInteger, %.2f, %@ for objects.
NSLog(@"Stock: %ld records", (long)stock);
NSLog(@"Top price: %.2f", price);
NSLog(@"Sunday? %@", openSunday ? @"open" : @"closed");
}
return 0;
}
Cómo funciona
NSIntegerydoubleson C plano con nombres de Cocoa.%ldimprime un NSInteger (con cast a long);%.2ffija decimales.- El ternario elige entre dos literales
@""para %@.
Palabras clave y builtins usados aquí
BOOLNOdoubleintlongreturnvoid
El intento, en números
- Líneas
- 16
- Caracteres a escribir
- 407
- Tokens
- 72
- Ritmo de tres estrellas
- 65 tpm
Al ritmo de tres estrellas de 65 tokens por minuto, este intento toma unos 66 segundos.
Paso 2 de 3 en Valores; paso 2 de 27 en Fundamentos del lenguaje.