views:

151

answers:

1

I have written a class to help save and load data for the sake of persistence for my iPhone application but I have a problem with some NSUIntegers that I'm passing across.

Basically, I have the code to use pointers, but eventually it has to start out being an actual value right? So I get this error

warning: passing argument 1 of 'getSaveWithCampaign:andLevel:' makes pointer from integer without a cast

My code is laid out like so.

(Persistence is the name of the class)

NSDictionary *saveData = [Persistence getSaveWithCampaign:currentCampaign andLevel:[indexPath row]];

Here's Persistence.m

#import "Persistence.h"


@implementation Persistence

+ (NSString *)dataFilePath
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    return [documentsDirectory stringByAppendingPathComponent:kSaveFilename];
}

+ (NSDictionary *)getSaveWithCampaign:(NSUInteger *)campaign andLevel:(NSUInteger *)level
{
    NSString *filePath = [self dataFilePath];

    if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
    {
        NSDictionary *saveData = [[NSDictionary alloc] initWithContentsOfFile:filePath];

        NSString *campaignAndLevelKey = [self makeCampaign:campaign andLevelKey:level];

        NSDictionary *campaignAndLevelData = [saveData objectForKey:campaignAndLevelKey];

        [saveData release];

        return campaignAndLevelData;
    }
    else
    {
        return nil;
    }

}

+ (NSString *)makeCampaign:(NSUInteger *)campaign andLevelKey:(NSUInteger *)level
{
    return [[NSString stringWithFormat:@"%d - ", campaign+1] stringByAppendingString:[NSString stringWithFormat:@"%d", level+1]];
}   

@end
+2  A: 

You should get rid of the * in ( NSUInteger *) in the getSaveWithCampaign method.

If you read the error message closely, it states that you are making a pointer (*) from an integer without a cast.

Your getSaveWithCampaign method should now have the following signature:

+ (NSDictionary *)getSaveWithCampaign:(NSUInteger)campaign andLevel:(NSUInteger)level

If, on the other hand, for some reason you do want to use pointers, you can pass in the NSUInteger prefixed with an ampersand (&) to pass in the address of the NSUInteger in memory.

Jacob Relkin
I'm really paranoid about memory usage, so I'm trying to use pointers as much as possible. Sounds kind of dumb for such small values. I'm trying the ampersand method, if that works I'll stick with it unless I get some headaches down the road.Thanks for your concise and prompt reply! Your help is greatly appreciated.
meridimus
As you can imagine, that comment before resulted in a wild goose chase of errors. I simple removed the need for pointers and I'm making progress. I think I was being too over the top with pointers and not really fully understanding how they're meant to be used.I am getting further.
meridimus