开发者

Add a (double) variable to NSMutableArray

I have a user input variable and i want to add that to an array. The firstStore is a BOOL type t determine if the array has been initialize. So the first time the STORE was called, it would initialize the array. I tried to make num equal to the operand (which is a double) by masking it NSNumber but that doesn't seem to work because i have this error "NSNumber may not respond to +operand", also the program crashes when it hits the line [memArray addObject:num]. I'm new at this stuff so any help would be greatly appreciated.

else if ([operation isEqual:@"Store"]) {
    if(!firstStore){
        memArray = [[NSMutableArray alloc] init];
        NSNumber *num = [NSNumber operand];
        [memArray addObject:num];
        firstStore = YES;
    } else {
         //NSNumber *num = [NSNumber operand];
        //[memArray addObject:num]开发者_如何学Go;
    }

}


Try changing [NSNumber operand] to [NSNumber numberWithDouble:operand].


"NSNumber may not respond to +operand" means what is says: There is no such class-method operand. What was it supposed to do?

You dont need a bool to track if memArray is initialized. use:

if(!memArray)

or

if (memArray == nil)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜