-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5c7f6d
commit f48f70e
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var optionalInteger: Int? | ||
optionalInteger = 404 | ||
|
||
if optionalInteger != nil { // 确定可选类型包含值后可以在变量名后加!强制解析 | ||
print(optionalInteger!) // 404 | ||
} | ||
|
||
|
||
var errorCode: Int? = 404 // 在类型后面添加一个? | ||
print(errorCode) // Optional(404) | ||
errorCode = nil // 对非可选类型赋值为nil会报错 | ||
print(errorCode) // nil | ||
|
||
// 确定可选类型包含值后可以在变量名后加!强制解析 | ||
if errorCode != nil { | ||
print(errorCode!)// 404 | ||
} |