Files
2021-12-14 09:36:26 +08:00

121 lines
2.8 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import UIKit
var greeting = "Hello, playground"
//: [Previous](@previous)
//: ###
// let
// 使
let age: Int
age = 31
let name = "Zhang Mengxu"
let sex: String = "man"
//: ###
// 使
//
//: ###
/*:
:
- value type
- reference type
value type
- enum:
Optional
- struct:
BoolIntFloatDoubleCharacterStringArrayDictionarySet
reference type
:
- class
*/
//: ####
/*:
Int8 Int16 Int32 Int64 UInt8 UInt16 UInt32 UInt64
32bitIntInt32, IntInt64
UInt8.max Int16.min
使Int
*/
let a:Int = 10
print(Int.max)
//: ####
/*:
Float,326Double6415
*/
let letFloat:Float = 30.0
let letDouble:Double = 30.0
//: ####
//
let bool = true
//
let string = "Zhang Mengxu"
//
let character: Character = "🐶"
//
let intDecimal = 17 //
let intBinary = 0b1001 //
let intOctal = 0o21 //
let intHexadecimal = 0x11 //
//
let doubleDecimal = 125.0 // 1.25e2 0.0125 1.25e-2
let doubleHexadecimal1 = 0xFp2 //15x2^260.0
let doubleHexadecimal2 = 0xFp-2 // 15x2^-23.75
//
let array = [1, 3, 5, 7]
//
let dictionary = ["name": 34, "age": 18]
//: ####
//
let int1: UInt16 = 2_000
let int2: UInt8 = 1
let int3 = int1 + UInt16(int2)
//
let int = 3
let double = 0.14159
let pi = Double(int) + double
let intpi = Int(pi)
//: #### tuple
//
let httpError = (404, "Not Found")
// 访
httpError.0
httpError.1
print("The status code is \(httpError.0)")
//
let (statusCode, statusMessage) = httpError
print("The status message is \(httpError.1)")
// -Not Found
let (justTheStatusCode, _) = httpError
// ,使访
let http200Status = (statusCode: 200, description: "ok")
print("The status code is \(http200Status.statusCode)")
//: [Next](@next)