---
title: "url(forKey:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/userdefaults/url(forkey:)"
---

# url(forKey:)

Returns the URL associated with the specified key.

## Declaration

```swift
func url(forKey defaultName: String) -> URL?
```

## Parameters

- `defaultName`: The key to retrieve from the defaults database.

## Return Value

Return Value The URL associated with defaultName, or nil if the key isn’t present in the defaults database.

## Discussion

Discussion This method uses the data for the specified key to create and return a URL type. If the key is present but the method can’t use it to create a URL, this method returns nil. If a file URL contains a tilde (~) character in its path, this method replaces the tilde with an expanded path. If you saved a bookmark URL for the key previously, use the URLByResolvingBookmarkData:options:relativeToURL:bookmarkDataIsStale:error: method to resolve the bookmark data and retrieve an equivalent file URL.

## See Also

### Getting the value of a key

- [bool(forKey:)](foundation/userdefaults/bool(forkey:).md)
- [integer(forKey:)](foundation/userdefaults/integer(forkey:).md)
- [float(forKey:)](foundation/userdefaults/float(forkey:).md)
- [double(forKey:)](foundation/userdefaults/double(forkey:).md)
- [string(forKey:)](foundation/userdefaults/string(forkey:).md)
- [stringArray(forKey:)](foundation/userdefaults/stringarray(forkey:).md)
- [data(forKey:)](foundation/userdefaults/data(forkey:).md)
- [object(forKey:)](foundation/userdefaults/object(forkey:).md)
- [array(forKey:)](foundation/userdefaults/array(forkey:).md)
- [dictionary(forKey:)](foundation/userdefaults/dictionary(forkey:).md)
- [dictionaryRepresentation()](foundation/userdefaults/dictionaryrepresentation().md)
