Public class: Makes pointer from integer without cast
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:file开发者_开发技巧Path];
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
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.
精彩评论