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

# attributedString(from:withDefaultAttributes:)

Returns a formatted postal address as an attributed string.

## Declaration

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

## Parameters

- `postalAddress`: The postal address to format.
- `attributes`: The default attributes to use. You can specify the doc://com.apple.contacts/documentation/Contacts/CNPostalAddressPropertyAttribute or doc://com.apple.contacts/documentation/Contacts/CNPostalAddressLocalizedPropertyNameAttribute attributes.

## 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:style:withDefaultAttributes:)](contacts/cnpostaladdressformatter/attributedstring(from:style:withdefaultattributes:).md)
- [CNPostalAddressPropertyAttribute](contacts/cnpostaladdresspropertyattribute.md)
- [CNPostalAddressLocalizedPropertyNameAttribute](contacts/cnpostaladdresslocalizedpropertynameattribute.md)
