The Swift Programming Language 2.1 Examples
源码在 GitHub:https://github.com/gewill/The-Swift-Programming-Language-2.1-Examples
大纲和都写着在注释里,废话不多说,咱们看代码 ->
swift
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
import UIKit
let http404Error = (404, "Not Found")
let (statusCode, statusMessage) = http404Error
http404Error.0
let http200Status = (statusCode: 200, description: "OK") http200Status.description
var serverResponseCode: Int? = 404 serverResponseCode = nil
var surveyAnswer: String?
let convertedNumber = Int("1")
if convertedNumber != nil { print(convertedNumber!) }
if let actualNumber = Int("32431") { print(actualNumber) }
let possibleString: String? = "An apple" let forcedString: String = possibleString!
let assumedString: String! = "" let implicitString: String = assumedString
func canThrowAnErrow() throws { }
do { try canThrowAnErrow() } catch { }
|