1
votes

I am setting up some constants, one being an NSDate but receiving this wanring message:

Incompatible pointer types initializing NSDate *const __strong with an expression of type NSString

Simple explanation of code (imp file):

NSDate *const kPAPUserBirthdayKey = @"fbBirthday";

Advanced explanation: I use a constants file as a singleton holding constant variables for the API i write to. For example the above which is a Date field which will hold the facebook users birthday when connecting to Facebook.

This is then later used in the following conversion:

// Convert the DOB string into Date format
NSDateFormatter* df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"MM/dd/yyyy"];
NSDate* userDOB = [df dateFromString:user.birthday];
[[PFUser currentUser] setObject:userDOB forKey:kPAPUserBirthdayKey];

Can someone explain what the warning actually means and what should be changed here? I get the same error on the last line of the above?

3

3 Answers

1
votes
NSDate *const kPAPUserBirthdayKey = @"fbBirthday";

You are assigning a string to a NSDate.

Change NSDate to NSString.

Use:

NSString const *kPAPUserBirthdayKey = @"fbBirthday";

Also check what you need ?

A constant pointer or pointer to a constant.

0
votes
NSDate *const kPAPUserBirthdayKey                               = @"fbBirthday";

Here fbBirthday is a string not date. The warning says that.

0
votes

Change your constant's type to NSString. The compiler is telling you you're making an assignment between incompatible types, as NSString is not a subclass of NSDate.