2009-06-02 7 views

Respuesta

17

Tendrá que utilizar NSNumber:

myArray = [NSMutableArray array]; 
[myArray addObject:[NSNumber numberWithInteger:1234]]; 

//.. 

int theNumber = [[myArray objectAtIndex:0] integerValue]; 
+1

Para evitar advertencias usan este, 'NSInteger Thenumber = [[myArray objectAtIndex: 0] IntegerValue];' o 'int Thenumber = [[myArray objectAtIndex: 0] intValue];' – Sachin

0

Tiene esto se extiende si quieres

Crear archivo extends.h añadir este código y import "extends.h" en su proyecto:

/*______________________________ Extends NSMutableArray ______________________________*/ 
/** 
* Extend NSMutableArray 
* By DaRkD0G 
*/ 
@interface NSMutableArray (NSArrayAdd) 
/** 
* Get element at index 
* 
* @param index 
*/ 
- (NSObject *) getAt:(int) index; 
@end 
/** 
* Extend NSMutableArray Method 
* By DaRkD0G 
*/ 
@implementation NSMutableArray (NSArrayAdd) 
/** 
* Get element at index 
* 
* @param index 
*/ 
- (NSObject *) getAt:(int) index { 
    NSInteger anIndex = index; 
    NSObject *object = [self objectAtIndex:anIndex]; 
    if (object == [NSNull null]) { 
     return nil; 
    } else { 
     NSLog(@"OK found "); 
     return object; 
    } 

} 
@end 
/*______________________________ Extends NSArray ______________________________*/ 
/** 
* Extend NSArray 
* By DaRkD0G 
*/ 
@interface NSArray (NSArrayAdd) 
/** 
* Get element at index 
* 
* @param index 
*/ 
- (NSObject *) getAt:(int) index; 
@end 
/** 
* Extend NSArray Method 
* By DaRkD0G 
*/ 
@implementation NSArray (NSArrayAdd) 
/** 
* Get element at index 
* 
* @param index 
*/ 
- (NSObject *) getAt:(int) index { 
    NSInteger anIndex = index; 
    NSObject *object = [self objectAtIndex:anIndex]; 
    if (object == [NSNull null]) { 
     return nil; 
    } else { 
     NSLog(@"OK found "); 
     return object; 
    } 

} 
@end 

USO:

NSObject object = [self.arrayItem getAt:0]; 
NSObject object2 = [self.arrayItem getAt:50]; 
Cuestiones relacionadas