SORU
22 EKİM 2010, Cuma


Nasıl NSMutableArray veya başka bir kap içinde bir NSRange mağaza?

Yapmak istediğim şey şu:

NSRange r = NSMakeRange(0,5);
id a = [NSMutableArray a];
[a addObject: r]; // but NSRange is not a NSObject *

Boole ile birlikte, bu gibi bir kod kullanmak istiyorum:

[a addObject: [NSNumber numberWithBool: YES]];

ya da bir tamsayı:

[a addObject: [NSNumber numberWithInteger: 3]];

NSRange ile eşdeğer nedir? Gerçekten yapmak istemiyorum ne bu başarmak için NSObject kendi alt oluşturun. Kesinlikle ne ile Apple zaten sağlanan bir yolu var mı?

CEVAP
22 EKİM 2010, Cuma


Use NSValue's valueWithRange:.

[a addObject:[NSValue valueWithRange:r]];
...

NSRange r = [[a objectAtIndex:4] rangeValue];

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Hey Nadine

    Hey Nadine

    24 Kasım 2006
  • We've moved!

    We've moved!

    7 Ocak 2008
  • TheXiaxue

    TheXiaxue

    3 AĞUSTOS 2009