---
title: "canBeConverted(to:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsstring/canbeconverted(to:)"
---

# canBeConverted(to:)

Returns a Boolean value that indicates whether the receiver can be converted to a given encoding without loss of information.

## Declaration

```swift
func canBeConverted(to encoding: UInt) -> Bool
```

## Parameters

- `encoding`: A string encoding. For possible values, see doc://com.apple.foundation/documentation/Foundation/NSStringEncoding.

## Return Value

Return Value true if the receiver can be converted to encoding without loss of information. Returns false if characters would have to be changed or deleted in the process of changing encodings.

## Discussion

Discussion If you plan to actually convert a string, the dataUsingEncoding:... methods return nil on failure, so you can avoid the overhead of invoking this method yourself by simply trying to convert the string.

## See Also

### Working with Encodings

- [availableStringEncodings](foundation/nsstring/availablestringencodings.md)
- [defaultCStringEncoding](foundation/nsstring/defaultcstringencoding.md)
- [stringEncoding(for:encodingOptions:convertedString:usedLossyConversion:)](foundation/nsstring/stringencoding(for:encodingoptions:convertedstring:usedlossyconversion:).md)
- [localizedName(of:)](foundation/nsstring/localizedname(of:).md)
- [data(using:)](foundation/nsstring/data(using:).md)
- [data(using:allowLossyConversion:)](foundation/nsstring/data(using:allowlossyconversion:).md)
- [description](foundation/nsstring/description.md)
- [fastestEncoding](foundation/nsstring/fastestencoding.md)
- [smallestEncoding](foundation/nsstring/smallestencoding.md)
- [StringEncodingDetectionOptionsKey](foundation/stringencodingdetectionoptionskey.md)
- [NSString Handling Exception Names](foundation/nsstring-handling-exception-names.md)
