Swift 命名规则

Swift可以使用几乎任何字符作为常量和变量名,包括Unicode,但是不能包含数字符号、箭头、无效的Unicode、横线-、制表符、且不能以数字开头。

var π = 3.14

 

var 新空气软件 = "开发软件"

 

let 你好 = "你好世界"

 

整形的表现形式

二进制:前缀0b

八进制:前缀0o

十六进制:前缀0x

let decimalInteger = 14

let binaryInteger = 0b10001

let octalInterger = 0o21

let hexadecimlInteger = 0x11

 

let minValue = UInt8.min

let maxValue = UInt8.max

UInt8 是一个结构体struct

{

public struct UInt8 : UnsignedIntegerType, Comparable, Equatable {

    public var value: Builtin.Int8

    /// A type that can represent the number of steps between pairs of

    /// values.

    public typealias Distance = Int

    /// Create an instance initialized to zero.

    public init()

    /// Create an instance initialized to `value`.

    public init(_ value: UInt8)

    public init(_builtinIntegerLiteral value: Builtin.Int2048)

    /// Create an instance initialized to `value`.

    public init(integerLiteral value: UInt8)

    public static var max: UInt8 { get }

    public static var min: UInt8 { get }


}

 

//类型别名

 

typealias NSInteger = Int

 

var value: NSInteger = 45

 

value = 12

 

print(value)

 

// 布尔类型

var tigerIsAnimal: Bool = true

 

1
原文地址:https://www.cnblogs.com/fantasy3588/p/5064993.html