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 入门指南
Cocoa
437
let d1 = Dog("Fido")
let d2 = Dog("Fido")
let ok = d1 == d2 // false
很多实现
isEqual:
类还实现了更为具体和高效的测试。对于
Objective-C
判断两个
NSNumber
对象是否相等(即包装了相同的数字)的常见做法是调
isEqualToNumber:
与之类似,
NSString
isEqualToString:
NSDate
isEqualToDate:
诸如此类。不过,这些类还实现
isEqual:
因此我觉得最好的方
式还是使用
Swift
==
算符。
与之类似,在
Objective-C
中,提供排序比较方法是每个类的职责。标准方法是
compare:
它会返回
3
NSComparisonResult case
之一:
.OrderedAscending
接收者小于参数。
.OrderedSame
接收者等于参数。
.OrderedDescending
接收者大于参数。
Swift
比较运算符(
<
类的)并不会神奇地调
compare:
。你不能直接比较两个
NSNumber
值:
let n1 = NSNumber(integer:1)
let n2 = NSNumber(integer:2)
let ok = n1 < n2 // compile error
你常常需要自己调用
compare:
就像在
Objective-C
中所做的那样:
let n1 = NSNumber(integer:1)
let n2
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