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

  • Bobbylee Budde

    Bobbylee Bud

    13 ŞUBAT 2011
  • buttheadgsxr1000

    buttheadgsxr

    24 Ocak 2008
  • hidetake takayama

    hidetake tak

    3 Mart 2009