Developer

MAFAddressFormatter

The MAFAddressFormatter formats phone numbers and addresses, and translates the names of the address fields.

As the formatter is implemented as a singleton, you can get access to any MAFAddressFormatter functionality by calling its class level instance method on the singleton instance:
[MAFAddressFormatter instance]
An address builds up from many fields, so you must set a collection of input values to work with the formatter. You can set up an NSDictionary that contains the keys prefixed with MAF_FORMATTER_ADDRESS_FIELD defined by MAF. For example:
[NSMutableArray arrayWithObjects:[NSMutableDictionary dictionaryWithObjects:
	[NSArray arrayWithObjects:
					 @"7",
					 @"Zahony",
					 @"Óbuda",
					 @"Budapest",
					 @"Pest",
					 @"1031",
					 @"Hungary",nil] 
		forKeys:[NSArray arrayWithObjects:
					MAF_FORMATTER_ADDRESS_FIELD_HOUSE_NO,
					MAF_FORMATTER_ADDRESS_FIELD_STREET,
					MAF_FORMATTER_ADDRESS_FIELD_LOCATION,
					MAF_FORMATTER_ADDRESS_FIELD_CITY,
					MAF_FORMATTER_ADDRESS_FIELD_REGION,
					MAF_FORMATTER_ADDRESS_FIELD_POSTL_COD1,
MAF_FORMATTER_ADDRESS_FIELD_COUNTRY,nil] ]
One public method directly outputs a full string that contains the full formatted address with newline characters:
- (NSString *)formattedAddressWithCountryCode:(NSString *)countryCode values:(NSDictionary *)values;
For example:
NSDictionary* addressInputValues = 
	[NSMutableArray arrayWithObjects:[NSMutableDictionary dictionaryWithObjects:
		[NSArray arrayWithObjects:
					 @"7",
					 @"Zahony",
					 @"Óbuda",
					 @"Budapest",
					 @"Pest",
					 @"1031",
					 @"Hungary",nil] 
			forKeys:[NSArray arrayWithObjects:
					MAF_FORMATTER_ADDRESS_FIELD_HOUSE_NO,
					MAF_FORMATTER_ADDRESS_FIELD_STREET,
					MAF_FORMATTER_ADDRESS_FIELD_LOCATION,
					MAF_FORMATTER_ADDRESS_FIELD_CITY,
					MAF_FORMATTER_ADDRESS_FIELD_REGION,
					MAF_FORMATTER_ADDRESS_FIELD_POSTL_COD1,
MAF_FORMATTER_ADDRESS_FIELD_COUNTRY,nil] ];

NSString* result = [[MAFAddressFormatter instance] formattedAddressWithCountryCode:@"HU" values:addressInputValues];
The other API methods query the layout information for an address. You can use them to create your own UI, specifying the number of fields, the title labels, and the values you need:
/**
 * Returns the number of rows for the specified country.
 * @param countryCode the country code
 * @returns the number of rows for the specified country
 */
- (NSUInteger)numberOfAddressRowsWithCountryCode:(NSString *)countryCode;


/**
 * Returns with the array of address rows with the specified values
 * @param valuesDict the values that make up the address to be displayed
 * @param countyCode_in the country code which we will format for
 * @returns the array of the address rows
 */
- (NSArray*)addressRowsWithValues:(NSDictionary*)valuesDict forCountryCode:(NSString*)countryCode_in;
The address rows with addressRowsWithCountryCode returns row-specific information in the form of an array of MADAddressEditableRow objects:
/**
 * Returns the rows for the specified country code. For country codes,
 * see the helper class. For values, see the header file.
 * @param countryCode the country code
 * @param values the values to be shown in the field (unspecified values will show the placeholder)
 * @returns the rows for the specified country code
 * @remark Probably, you doesn't need to call this, because it's automatically stored when you create the instance or set another locale and used in getAddressRowsWithValues:.
 */
- (NSArray *)addressRowsWithCountryCode:(NSString *)countryCode;