Damian Van de Kauter Damian Van de Kauter - 5 months ago 13
iOS Question

Custom function not returning correct value

I have a code to create my own function but it gives me a warning:


  • Incompatible integer to pointer conversion assigning to 'SMUserKey *' (aka 'unsigned long *') from 'int'

  • Incompatible integer to pointer conversion sending 'SMUserKey' (aka 'unsigned long') to parameter of type 'SMUserKey *' (aka 'unsigned long *')



So it's showing warning and I want to get rid of them.

This is my .h code:

typedef NSUInteger SMUserKey;


NS_ENUM(SMUserKey) {
SMUsername = 1,
SMFirstName = 2,
SMLastName = 3,
SMFullName = 4,
SMEmail = 5,
};


This is my .m code:

-(void)awakeFromNib {
NSString *result = [SMUser getValueForKey:SMUsername];
NSLog(@"THE RESULT: %@", result);
}

+ (NSString *)getValueForKey:(SMUserKey*)myUserKey {
NSString *myUserKeyValue = nil;
if (myUserKey == 1) {
myUserKeyValue = @"Username";
}
if (myUserKey == 2) {
myUserKeyValue = @"First Name";
}
if (myUserKey == 3) {
myUserKeyValue = @"Last Name";
}
if (myUserKey == 4) {
myUserKeyValue = @"Full Name";
}
if (myUserKey == 5) {
myUserKeyValue = @"Email";
}
return myUserKeyValue;
}


This is the image showing the warnings:

Click here to see the image

Answer

This should do it.

-(void)awakeFromNib {
    NSString *result = [SMUser getValueForKey:SMUsername];
    NSLog(@"THE RESULT: %@", result);
}

+ (NSString *)getValueForKey:(SMUserKey*)myUserKey {
    NSString *myUserKeyValue = nil;
    if (myUserKey == 1) {
        myUserKeyValue = @"Username";
    }
    if (myUserKey == 2) {
        myUserKeyValue = @"First Name";
    }
    if (myUserKey == 3) {
        myUserKeyValue = @"Last Name";
    }
    if (myUserKey == 4) {
        myUserKeyValue = @"Full Name";
    }
    if (myUserKey == 5) {
        myUserKeyValue = @"Email";
    }
    return myUserKeyValue;
}
Comments