Skip to content

Commit 9b0b27e

Browse files
authored
Merge pull request #4235 from trentxintong/ChangeLog
Add changelog for SE-0128
2 parents f3c0c71 + 5fc21eb commit 9b0b27e

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
@@ -3,6 +3,33 @@ Note: This is in reverse chronological order, so newer entries are added to the
33
Swift 3.0
44
---------
55

6+
* [SE-0128](https://github.com/apple/swift-evolution/blob/master/proposals/0128-unicodescalar-failable-initializer.md)
7+
8+
Some UnicodeScalar initializers (ones that are non-failable) now return an Optional,
9+
i.e., in case a UnicodeScalar can not be constructed, nil is returned.
10+
11+
```swift
12+
// Old
13+
var string = ""
14+
let codepoint: UInt32 = 55357 // this is invalid
15+
let ucode = UnicodeScalar(codepoint) // Program crashes at this point.
16+
string.append(ucode)
17+
```
18+
19+
After marking the initializer as failable, users can write code like this and the
20+
program will execute fine even if the codepoint isn't valid.
21+
22+
```swift
23+
// New
24+
var string = ""
25+
let codepoint: UInt32 = 55357 // this is invalid
26+
if let ucode = UnicodeScalar(codepoint) {
27+
string.append(ucode)
28+
} else {
29+
// do something else
30+
}
31+
```
32+
633
* [SE-103](https://github.com/apple/swift-evolution/blob/master/proposals/0103-make-noescape-default.md)
734

835
Closure parameters are non-escaping by default, rather than explicitly being

0 commit comments

Comments
 (0)