0

Hi when I try to save a phonenumber with this line to a coredata element

            [newLead setValue:[NSNumber numberWithInteger:[self.cellTextField.text doubleValue] ] forKey:@"cell"];

Then I load it with this

    [self.cellTextField setText:[[self.lead valueForKey:@"cell"] stringValue]];

It works but if the number is like 905666777 , that number is too big and i get 2147483647

How can i make it use a 905 number?

also when i dial the number using

     NSURL *telUrl = [NSURL URLWithString:[@"tel://" stringByAppendingString:@"cell"]];
[[UIApplication sharedApplication] openURL:telUrl]; 

It only dials the first 3 digits 214, how can i make it dial all the digits

Thank you

  • The first line should read `[newLead setValue:[NSNumber numberWithInteger:[self.cellTextField.text integerValue] ] forKey:@"cell"];` with **integerValue** instead of doubleValue – bachonk Jul 21 '13 at 03:49
  • @bachonk yeah i caught that and fixed it but still – James Callyway Jul 21 '13 at 04:02

1 Answers1

3

The problem is that you're saving a phone number as a numeric value, so you're running into limits on numeric types. There's no reason to do this this-- you should be using a string. You'll never do math on the phone number, for example. Any fetches you might do (for example finding phone numbers with a specific area code) will be more difficult with a numeric type than with a string.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170
  • 1
    Agreed. Phone numbers are not simply numbers and should never be treated as such. International numbers start with `+` and may contain parentheses, and many phone numbers contain leading zeroes that must be preserved. – Jim Jul 22 '13 at 16:31