Skip to content

Commit cb31763

Browse files
committed
Add a changelog for SE-128
1 parent a6f3eb1 commit cb31763

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,33 @@ Swift 3.0
221221
The `hasPrefix` and `hasSuffix` functions now consider the empty string to be a
222222
prefix and suffix of all strings.
223223

224+
* [SE-128](https://github.com/apple/swift-evolution/blob/master/proposals/0128-unicodescalar-failable-initializer.md)
225+
226+
Some UnicodeScalar initializers (ones that are non-failable) now returns an Optional,
227+
i.e., in case a UnicodeScalar can not be constructed, nil is returned.
228+
229+
```swift
230+
// Old
231+
var string = ""
232+
let codepoint: UInt32 = 55357 // this is invalid
233+
let ucode = UnicodeScalar(codepoint) // Program crashes at this point.
234+
string.append(ucode)
235+
```
236+
237+
After marking the initializer as failable, users can write code like this and the
238+
program will execute fine even if the codepoint isn't valid.
239+
240+
```swift
241+
// New
242+
var string = ""
243+
let codepoint: UInt32 = 55357 // this is invalid
244+
if let ucode = UnicodeScalar(codepoint) {
245+
string.append(ucode)
246+
} else {
247+
// do something else
248+
}
249+
```
250+
224251
* [SE-0095](https://github.com/apple/swift-evolution/blob/master/proposals/0095-any-as-existential.md):
225252
The `protocol<...>` composition construct has been removed. In its
226253
place, an infix type operator `&` has been introduced.

0 commit comments

Comments
 (0)