If you are using a data detector with type NSTextCheckingTypeAddress
, the returned matches should provide an addressComponents dictionary.
That dictionary contains all the keys you mentioned.
NSDataDetector* detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeAddress error:nil];
NSString* addressString = @"Apple, 1 Infinite Loop, Cupertino, CA";
NSArray* matches = [detector matchesInString:addressString options:0 range:NSMakeRange(0, addressString.length)];
for(NSTextCheckingResult* match in matches)
{
if(match.resultType == NSTextCheckingTypeAddress)
{
NSDictionary* addressComponents = [match addressComponents];
NSLog(@"Address Dictionary:%@", addressComponents);
}
}
The above snippet returns the following for the input string:
Address Dictionary:{
City = Cupertino;
State = CA;
Street = "1 Infinite Loop";
}
A fully featured address string would result in values for the following keys:
NSTextCheckingNameKey
NSTextCheckingJobTitleKey
NSTextCheckingOrganizationKey
NSTextCheckingStreetKey
NSTextCheckingCityKey
NSTextCheckingStateKey
NSTextCheckingZIPKey
NSTextCheckingCountryKey
NSTextCheckingPhoneKey
NSTextCheckingAirlineKey
NSTextCheckingFlightKey