MAF Formatter Types

Formatter types include: MAFAddressFormatter class for phone numbers and address field layout information, MAFDateTimeFormatter for date times, and MAFCurrencyFormatter for currencies.

High-level steps for using the formatters:
  1. Instantiate the classes by MAF, either by using factory objects or by directly allocating and initializing them.
  2. Specify settings and parameters for the formatter instances.
  3. Format your data.

Metadata

All three types of formatters use metadata to format input values according to the predefined locale, country, and custom settings.

For MAFDateTimeFormatter, the metadata comes from and is handled completely by the iOS frameworks. The formatter uses the NSDate class to format date and time values according to locale and country settings.

For MAFAddressFormatter and MAFCurrencyFormatter, the metadata is loaded from the default XML and .plist resource files provided with MAF. You can easily configure these files if necessary.

Generic Country Codes Information

A regular Xcode project .plist file lists the country codes with the corresponding country names. The processed and parsed output is used by the MAFAddressFormatter. MAF also provides a MAFCountryCodeStore class that you can use to query the country code for a country and vice versa. This class and its query methods are available via the public MAF API.

Currency Formatter Specific Metadata

MAFCurrencyFormatter uses metadata (an XML file) to build up an internal runtime data store to determine the currency names and alphabetic codes for countries. This runtime currency data store is not available via the MAF API; it is used only by the formatters. This sample shows the currency-related information for Hungary:
 <ISO_CURRENCY>
	<ENTITY>HUNGARY</ENTITY>
	<CURRENCY>Forint</CURRENCY>
	<ALPHABETIC_CODE>HUF</ALPHABETIC_CODE>
	<NUMERIC_CODE>348</NUMERIC_CODE>
	<MINOR_UNIT>2</MINOR_UNIT>
</ISO_CURRENCY>

Address and Phone Number Formatters Specific Metadata

The XML metadata that MAFAddressFormatter uses contains country-code-specific information that describes:
  • The address layout: types and order of address fields to show, and the number of lines to display the address in.
  • Local and international phone number formats.

This information is also available in the low- and high-level public MAF APIs of the MAFAddressFormatter class. See the public API in the corresponding header file (MAFAddressFormatter.h), and the MAFAddressFormatter section.

This sample shows the XML metadata for Hungary:
<!-- Hungary -->
<format country="hu">

	<addresses>
		<address format="POSTL_COD1 CITY\nSTREET HOUSE_NO\nLOCATION\nCOUNTRY" />
	</addresses>

	<addressfields>
		<line>
			<field id="POSTL_COD1" keyboard="NUMERIC" label="{POSTAL_CODE}" />
			<field id="CITY" label="{CITY}" />
		</line>
		<line>
			<field id="STREET" width="65%" label="{STREET}" />
			<field id="HOUSE_NO" keyboard="NUMERIC" width="35%" label="No." />
		</line>
		<line>
			<field id="LOCATION" label="{STREET} 4" />
		</line>
		<line>
			<field id="COUNTRY" label="{COUNTRY}" />
		</line>
	</addressfields>

	<phonenumbers localprefix="06" internationalprefix="36 " outboundcode="00">
		<phonenumber format="06 1 xxx-xxxx" />
		<phonenumber format="06 xx xxx-xxx" />
		<phonenumber format="06 xx xxx-xxxx" />
	</phonenumbers>

</format>