Skip to Main Content
iOS 编程基础:Swift、Xcode 和Cocoa 入门指南
book

iOS 编程基础:Swift、Xcode 和Cocoa 入门指南

by Matt Neuburg
January 2017
Intermediate to advanced content levelIntermediate to advanced
552 pages
9h 43m
Chinese
China Machine Press
Content preview from iOS 编程基础:Swift、Xcode 和Cocoa 入门指南
512
附录
A
CGPoint p;
p.x = 100;
p.y = 200;
C
结构体进入
Swift
中后就会变成
Swift
结构体,然后就拥有了
Swift
结构体的特性。比
如,
Swift
中的
CGPoint
会拥有
x
y
CGPoint
实例属性;不过,它还会神奇地拥有隐
式的成员初始化器!此外,还会注入一个不带参数的初始化器;因此,
CGPoint()
一个
x
y
都为
0
CGPoint
。扩展可以提供额外的特性,
Swift CoreGraphics
头会
CGPoint
添加一些:
extension CGPoint {
static var zeroPoint: CGPoint { get }
init(x: Int, y: Int)
init(x: Double, y: Double)
}
如你所见,
Swift CGPoint
拥有一些额外的初始化器,接收
Int
Double
参数,还有另外
一种创建
0
CGPoint
的方式
CGPoint.zeroPoint
CGSize
与之类似。特别地,
Swift
中的
CGRect
还会拥有额外的方法与属性;如果无法通过
Core Graphics
框架提供的内建
C
函数来操纵
CGRect
,那么你也不能通过这些额外的方法实现;不过,你可以以
Swift
的方式来做到这一点。
Swift
结构体是对象,
C
结构体却不是,不过这一点并不会对通信造成任何影响。比如,
你可以在需要
C CGPoint
时赋值或传递一个
Swift CGPoint
,因
CGPoint
首先来自于
C
Swift ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

机器学习实战:基于Scikit-Learn、Keras 和TensorFlow (原书第2 版)

Aurélien Géron
Swift 人工智能实战:从基础理论到AI 驱动的应用程序开发

Swift 人工智能实战:从基础理论到AI 驱动的应用程序开发

Mars Geldard, Jonathon Manning, Paris Buttfield-Addison, Tim Nugent

Publisher Resources

ISBN: 9787111556350