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

  • andony5589

    andony5589

    7 Aralık 2011
  • fast2hell

    fast2hell

    16 AĞUSTOS 2006
  • Jaclyn W

    Jaclyn W

    5 Mayıs 2006