1

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?

kelin
  • 11,323
  • 6
  • 67
  • 104
StuartM
  • 6,743
  • 18
  • 84
  • 160

3 Answers3

1
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.

Community
  • 1
  • 1
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
  • @CarlVeazey: sorry yet again typo miss, explained good but copied and forgot to change nsdate to nsstring :( And you are very frequent to downvote. NO mercy what so ever. – Anoop Vaidya Mar 22 '13 at 15:57
  • Ok, I guess this relates more to how this is being used/implemented. fbBirthday is a string correct however that is simply the title/column the date will then be input into. So the actual data being input would be a Date, shown here - [[PFUser currentUser] setObject:userDOB forKey:kPAPUserBirthdayKey]; – StuartM Mar 22 '13 at 16:01
0
NSDate *const kPAPUserBirthdayKey                               = @"fbBirthday";

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

Vignesh
  • 10,205
  • 2
  • 35
  • 73
0

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.

Carl Veazey
  • 18,392
  • 8
  • 66
  • 81