views:

29

answers:

1

I need a value to be calculated in it's getter method if it isn't set already. I prefer to use a nullable int construction, so I don't need another bool to check if it's already been calculated.

My first hunch was to go for a NSInteger *. I can check if it's NULL and otherwise set a value to it. But I don't know if it's possible, since I can't really get a value assigned to it.

    if (!value)
    {
        value = [self calcValue]; 
    }
    return value;

This leads to Assignment makes pointer from integer without cast and Return makes integer from pointer without a cast.

How would I assign a int to a NSInteger *?
How would I cast a NSInteger * to a int?

Or: what is a better solution to this problem?

A: 

An NSInteger is actually an int. You're looking for NSNumber, which lets you treat numbers as objects.

mvds