File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -221,6 +221,33 @@ Swift 3.0
221
221
The `hasPrefix` and `hasSuffix` functions now consider the empty string to be a
222
222
prefix and suffix of all strings.
223
223
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
+
224
251
* [SE- 0095 ](https :// github.com/apple/swift-evolution/blob/master/proposals/0095-any-as-existential.md):
225
252
The `protocol< ...> ` composition construct has been removed. In its
226
253
place, an infix type operator `& ` has been introduced.
You can’t perform that action at this time.
0 commit comments