---
title: "attributedString(from:style:withDefaultAttributes:)"
framework: contacts
role: symbol
role_heading: Type Method
path: "contacts/cnpostaladdressformatter/attributedstring(from:style:withdefaultattributes:)"
---

# attributedString(from:style:withDefaultAttributes:)

Returns a postal address as an attributed string and formatted for the specified style.

## Declaration

```swift
class func attributedString(from postalAddress: CNPostalAddress, style: CNPostalAddressFormatterStyle, withDefaultAttributes attributes: [AnyHashable : Any] = [:]) -> NSAttributedString
```

## Parameters

- `postalAddress`: The postal address to format.
- `style`: The postal formatting style to use. For a list of possible values, see doc://com.apple.contacts/documentation/Contacts/CNPostalAddressFormatterStyle.
- `attributes`: The default attributes to use. To learn more, see Formatter.

## Return Value

Return Value The formatted postal address as an attributed string. Discussion This method behaves similarly to  string(from:), except that it returns an attributed string. It includes the attribute key CNPostalAddressPropertyAttribute, whose attribute values are postal address property keys, such as CNPostalAddressStreetKey. This identifies the postal address components in the formatted postal address. It also includes the attribute key CNPostalAddressLocalizedPropertyNameAttribute whose attribute values are the localized strings for the postal address property keys.

## See Also

### Generating a formatted attributed string

- [attributedString(from:withDefaultAttributes:)](contacts/cnpostaladdressformatter/attributedstring(from:withdefaultattributes:).md)
- [CNPostalAddressPropertyAttribute](contacts/cnpostaladdresspropertyattribute.md)
- [CNPostalAddressLocalizedPropertyNameAttribute](contacts/cnpostaladdresslocalizedpropertynameattribute.md)
