Swift 命名规则
2015-12-21 21:50
471 查看
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
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
相关文章推荐
- Swift 数据类型
- iOS --- Swift中泛型(Generic)的基本使用
- iOS集成丁香园DXY OAuth 登陆 swift代码示例
- swift中判断设备是否打开定位
- 项目开发笔记-2015.12.21-swift
- Swift Tutorial: Repeating Steps with Loops
- swift 新功能介绍
- Swift 已经正式开源了! 你了解到了吗?
- Swift 设置按钮圆角 代码&Xib
- Swift - 初次使用:
- swift禁止横屏
- swift 学习记录(静态属性)
- swift 基础知识
- swift学习记录(计算属性和属性观察者)
- swift学习记录(存储属性)
- <swift学习之路> UIAlertController的简单使用
- swift Touch ID 的简单使用 指纹识别
- swift 学习记录(类和结构体)
- 《从零开始学Swift》学习笔记(Day 50)——扩展计算属性、方法
- 《从零开始学Swift》学习笔记(Day 50)——扩展计算属性、方法