没有合适的资源?快使用搜索试试~ 我知道了~
首页Objective-C编程实践指南
Objective-C编程实践指南
5星 · 超过95%的资源 需积分: 10 2 下载量 152 浏览量
更新于2024-07-20
收藏 27.03MB PDF 举报
"Objective-C Recipes: A Problem-Solution Approach by Matthew Campbell"
本书《Objective-C Recipes》是针对Objective-C编程的关键方面提供问题解决方案的指南,旨在帮助读者有效地执行常见的编程任务。作者Matthew Campbell通过实例展示了如何利用Objective-C编程语言的独特特性、Foundation框架的实用功能以及Objective-J作为替代选项的优势。
Objective-C是Apple开发的一种面向对象的编程语言,主要用于iOS和macOS应用开发。它基于C语言,增加了Smalltalk式的消息传递机制和类定义等面向对象特性。Objective-C的特性包括:
1. **动态类型**:Objective-C支持在运行时确定对象的类型,这使得代码更加灵活,但同时也可能导致一些类型安全问题。
2. **消息传递**:Objective-C中的方法调用实际上是一种消息传递机制,对象通过接收并处理消息来执行操作。
3. **协议(Protocols)**:Objective-C的协议类似于Java或C#的接口,定义了一组方法签名,允许类实现多个行为,而无需继承。
4. **Category(分类)**:Objective-C的分类允许在不修改原有类源码的情况下扩展其功能,这对于开源库的扩展和维护非常有用。
5. **Blocks(区块/闭包)**:Objective-C引入了类似C++ lambda表达式或JavaScript函数字面量的区块,用于定义可嵌套的代码块,常用于异步操作回调。
Foundation框架是Objective-C开发的基础,它包含了各种数据类型、集合类、线程管理、文件系统操作等功能。例如:
1. **NSArray和NSMutableArray**:分别代表不可变和可变的有序对象集合,提供了遍历和操作对象数组的方法。
2. **NSDictionary和NSMutableDictionary**:表示键值对的不可变和可变容器,方便地存储和检索数据。
3. **NSString**:处理文本字符串的强大类,支持格式化、搜索、替换等操作。
4. **NSThread和NSOperationQueue**:用于多线程和并发编程,NSOperationQueue还支持依赖关系和优先级设置。
Objective-J是Cappuccino框架的一部分,它是一种JavaScript方言,设计用来编写桌面级的Web应用程序。Objective-J提供了与Objective-C相似的语法,使得熟悉Objective-C的开发者可以更容易地迁移到Web开发。
在书中,作者将介绍如何利用这些工具和概念解决实际编程问题,包括错误处理、内存管理(在iOS中主要是ARC,即自动引用计数)、UI设计与交互、网络编程、数据持久化等。通过这本书,读者不仅可以深入理解Objective-C,还能提升实际项目中的开发效率。
■
■
CONTENTS
The
Code
.............................................................................................................................................................
238
Usage
..................................................................................................................................................................
241
Chapter
7:
Consuming
Web
Content
............................................................
243
7.1
Downloading
a
File
...................................................................................
243
Problem
..............................................................................................................................................................
243
Solution
..............................................................................................................................................................
243
How
It
Works
......................................................................................................................................................
244
The
Code
.............................................................................................................................................................
244
Usage
..................................................................................................................................................................
245
7.2
Consuming
a
Web
Service
Using
XML
.......................................................
245
Problem
..............................................................................................................................................................
245
Solution
..............................................................................................................................................................
246
How
It
Works
......................................................................................................................................................
246
The
Code
.............................................................................................................................................................
251
Usage
..................................................................................................................................................................
252
7.3
Consuming
a
Web
Service
Using
JSON
.....................................................
253
Problem
..............................................................................................................................................................
253
Solution
..............................................................................................................................................................
253
How
It
Works
......................................................................................................................................................
254
The
Code
.............................................................................................................................................................
255
Usage
..................................................................................................................................................................
256
7.4
Asynchronously
Consuming
Web
Content
................................................
257
Problem
..............................................................................................................................................................
257
Solution
..............................................................................................................................................................
257
How
It
Works
......................................................................................................................................................
257
The
Code
.............................................................................................................................................................
259
Usage
..................................................................................................................................................................
260
Chapter
8:
Memory
Management
................................................................
261
B.1
Understanding
Memory
Management
.......................................................
261
Problem
..............................................................................................................................................................
261
Solution
..............................................................................................................................................................
261
8.2
Setting
up
an
Application
without
ARC
.....................................................
265
Problem
..............................................................................................................................................................
265
Solution
..............................................................................................................................................................
265
How
It
Works
......................................................................................................................................................
265
The
Code
.............................................................................................................................................................
266
Usage
..................................................................................................................................................................
267
8.3
Using
Reference
Counting
to
Manage
Memory
.........................................
267
Problem
..............................................................................................................................................................
267
Solution
..............................................................................................................................................................
267
How
It
Works
......................................................................................................................................................
267
xv
CONTENTS
The
Code
.............................................................................................................................................................
238
Usage
..................................................................................................................................................................
241
Chapter
7:
Consuming
Web
Content
............................................................
243
7.1
Downloading
a
File
...................................................................................
243
Problem
..............................................................................................................................................................
243
Solution
..............................................................................................................................................................
243
How
It
Works
......................................................................................................................................................
244
The
Code
.............................................................................................................................................................
244
Usage
..................................................................................................................................................................
245
7.2
Consuming
a
Web
Service
Using
XML
.......................................................
245
Problem
..............................................................................................................................................................
245
Solution
..............................................................................................................................................................
246
How
It
Works
......................................................................................................................................................
246
The
Code
.............................................................................................................................................................
251
Usage
..................................................................................................................................................................
252
7.3
Consuming
a
Web
Service
Using
JSON
.....................................................
253
Problem
..............................................................................................................................................................
253
Solution
..............................................................................................................................................................
253
How
It
Works
......................................................................................................................................................
254
The
Code
.............................................................................................................................................................
255
Usage
..................................................................................................................................................................
256
7.4
Asynchronously
Consuming
Web
Content
................................................
257
Problem
..............................................................................................................................................................
257
Solution
..............................................................................................................................................................
257
How
It
Works
......................................................................................................................................................
257
The
Code
.............................................................................................................................................................
259
Usage
..................................................................................................................................................................
260
Chapter
8:
Memory
Management
................................................................
261
B.1
Understanding
Memory
Management
.......................................................
261
Problem
..............................................................................................................................................................
261
Solution
..............................................................................................................................................................
261
8.2
Setting
up
an
Application
without
ARC
.....................................................
265
Problem
..............................................................................................................................................................
265
Solution
..............................................................................................................................................................
265
How
It
Works
......................................................................................................................................................
265
The
Code
.............................................................................................................................................................
266
Usage
..................................................................................................................................................................
267
8.3
Using
Reference
Counting
to
Manage
Memory
.........................................
267
Problem
..............................................................................................................................................................
267
Solution
..............................................................................................................................................................
267
How
It
Works
......................................................................................................................................................
267
xv
■
CONTENTS
The
Code
.............................................................................................................................................................
269
Usage
..................................................................................................................................................................
270
8.4
Adding
Memory
Management
to
Your
Custom
Classes
............................
270
Problem
..............................................................................................................................................................
270
Solution
..............................................................................................................................................................
270
How
It
Works
......................................................................................................................................................
270
The
Code
.............................................................................................................................................................
273
Usage
..................................................................................................................................................................
274
8.5
Using
Autorelease
.....................................................................................
275
Problem
..............................................................................................................................................................
275
Solution
..............................................................................................................................................................
275
How
It
Works
......................................................................................................................................................
275
The
Code
.............................................................................................................................................................
277
Usage
..................................................................................................................................................................
280
8.6
Enabling
Garbage
Collection
for
Mac
Applications
...................................
280
Problem
..............................................................................................................................................................
280
Solution
..............................................................................................................................................................
280
How
It
Works
......................................................................................................................................................
281
Chapter
9:
Working
With
Object
Graphs
......................................................
283
Object-Orientated
Vocabulary
.........................................................................
283
Entity
.................................................................................................................................................................
283
Class .................................................................................................................................................................
284
Objects .............................................................................................................................................................
284
The Object Graph ..........................................................................................................................................
284
9.1
Creating
an
Object
Graph
..........................................................................
285
Problem
..............................................................................................................................................................
285
Solution
..............................................................................................................................................................
285
How It Works ..................................................................................................................................................
285
The
Code
.............................................................................................................................................................
292
Usage
..................................................................................................................................................................
296
9.2
Using
Key-Value
Coding
............................................................................
297
Problem
..............................................................................................................................................................
297
Solution
..............................................................................................................................................................
297
How
It
Works
......................................................................................................................................................
297
The
Code
.............................................................................................................................................................
300
Usage
..................................................................................................................................................................
304
9.3
Using
Key
Paths
in
Your
Object
Graph
Problem
••••••••••••••••••••••••••••••••••••••••
305
Solution
..............................................................................................................................................................
305
How
It
Works
......................................................................................................................................................
305
The
Code
.............................................................................................................................................................
306
Usage
..................................................................................................................................................................
310
xvi
CONTENTS
The
Code
.............................................................................................................................................................
269
Usage
..................................................................................................................................................................
270
8.4
Adding
Memory
Management
to
Your
Custom
Classes
............................
270
Problem
..............................................................................................................................................................
270
Solution
..............................................................................................................................................................
270
How
It
Works
......................................................................................................................................................
270
The
Code
.............................................................................................................................................................
273
Usage
..................................................................................................................................................................
274
8.5
Using
Autorelease
.....................................................................................
275
Problem
..............................................................................................................................................................
275
Solution
..............................................................................................................................................................
275
How
It
Works
......................................................................................................................................................
275
The
Code
.............................................................................................................................................................
277
Usage
..................................................................................................................................................................
280
8.6
Enabling
Garbage
Collection
for
Mac
Applications
...................................
280
Problem
..............................................................................................................................................................
280
Solution
..............................................................................................................................................................
280
How
It
Works
......................................................................................................................................................
281
Chapter
9:
Working
With
Object
Graphs
......................................................
283
Object-Orientated
Vocabulary
.........................................................................
283
Entity
.................................................................................................................................................................
283
Class .................................................................................................................................................................
284
Objects .............................................................................................................................................................
284
The Object Graph ..........................................................................................................................................
284
9.1
Creating
an
Object
Graph
..........................................................................
285
Problem
..............................................................................................................................................................
285
Solution
..............................................................................................................................................................
285
How It Works ..................................................................................................................................................
285
The
Code
.............................................................................................................................................................
292
Usage
..................................................................................................................................................................
296
9.2
Using
Key-Value
Coding
............................................................................
297
Problem
..............................................................................................................................................................
297
Solution
..............................................................................................................................................................
297
How
It
Works
......................................................................................................................................................
297
The
Code
.............................................................................................................................................................
300
Usage
..................................................................................................................................................................
304
9.3
Using
Key
Paths
in
Your
Object
Graph
Problem
••••••••••••••••••••••••••••••••••••••••
305
Solution
..............................................................................................................................................................
305
How
It
Works
......................................................................................................................................................
305
The
Code
.............................................................................................................................................................
306
Usage
..................................................................................................................................................................
310
xvi
■
CONTENTS
9.4
Aggregating
Information
with
Key
Paths
..................................................
311
Problem
..............................................................................................................................................................
311
Solution
..............................................................................................................................................................
312
How
It
Works
......................................................................................................................................................
312
The
Gode
.............................................................................................................................................................
313
Usage
..................................................................................................................................................................
317
9.5
Implementing
the
Observer
Pattern
..........................................................
318
Problem
..............................................................................................................................................................
318
Solution
..............................................................................................................................................................
318
How
It
Works
......................................................................................................................................................
318
The
Gode
.............................................................................................................................................................
320
Usage
..................................................................................................................................................................
323
9.6
Inspecting
Classes
and
Objects
................................................................
323
Problem
..............................................................................................................................................................
323
Solution
..............................................................................................................................................................
323
How
It
Works
......................................................................................................................................................
323
The
Gode
.............................................................................................................................................................
326
Usage
..................................................................................................................................................................
329
9.7
Archiving
Your
Object
Graph
.....................................................................
330
Problem
..............................................................................................................................................................
330
Solution
..............................................................................................................................................................
330
How
It
Works
......................................................................................................................................................
330
The
Gode
.............................................................................................................................................................
332
Usage
..................................................................................................................................................................
337
Chapter
10:
Core
Data
.................................................................................
339
10.1
Adding
Core
Data
Support
to
an
Application
..........................................
340
Problem
..............................................................................................................................................................
340
Solution
..............................................................................................................................................................
340
The
Gode
.............................................................................................................................................................
346
Usage
..................................................................................................................................................................
348
10.2
Adding
an
Entity
Description
..................................................................
348
Problem
..............................................................................................................................................................
348
Solution
..............................................................................................................................................................
349
How
It
Works
......................................................................................................................................................
349
The
Gode
.............................................................................................................................................................
351
Usage
..................................................................................................................................................................
352
10.3
Adding
a
Managed
Object
to
an
Application
...........................................
352
Problem
..............................................................................................................................................................
352
Solution
..............................................................................................................................................................
352
How
It
Works
......................................................................................................................................................
352
The
Gode
.............................................................................................................................................................
354
xvii
CONTENTS
9.4
Aggregating
Information
with
Key
Paths
..................................................
311
Problem
..............................................................................................................................................................
311
Solution
..............................................................................................................................................................
312
How
It
Works
......................................................................................................................................................
312
The
Gode
.............................................................................................................................................................
313
Usage
..................................................................................................................................................................
317
9.5
Implementing
the
Observer
Pattern
..........................................................
318
Problem
..............................................................................................................................................................
318
Solution
..............................................................................................................................................................
318
How
It
Works
......................................................................................................................................................
318
The
Gode
.............................................................................................................................................................
320
Usage
..................................................................................................................................................................
323
9.6
Inspecting
Classes
and
Objects
................................................................
323
Problem
..............................................................................................................................................................
323
Solution
..............................................................................................................................................................
323
How
It
Works
......................................................................................................................................................
323
The
Gode
.............................................................................................................................................................
326
Usage
..................................................................................................................................................................
329
9.7
Archiving
Your
Object
Graph
.....................................................................
330
Problem
..............................................................................................................................................................
330
Solution
..............................................................................................................................................................
330
How
It
Works
......................................................................................................................................................
330
The
Gode
.............................................................................................................................................................
332
Usage
..................................................................................................................................................................
337
Chapter
10:
Core
Data
.................................................................................
339
10.1
Adding
Core
Data
Support
to
an
Application
..........................................
340
Problem
..............................................................................................................................................................
340
Solution
..............................................................................................................................................................
340
The
Gode
.............................................................................................................................................................
346
Usage
..................................................................................................................................................................
348
10.2
Adding
an
Entity
Description
..................................................................
348
Problem
..............................................................................................................................................................
348
Solution
..............................................................................................................................................................
349
How
It
Works
......................................................................................................................................................
349
The
Gode
.............................................................................................................................................................
351
Usage
..................................................................................................................................................................
352
10.3
Adding
a
Managed
Object
to
an
Application
...........................................
352
Problem
..............................................................................................................................................................
352
Solution
..............................................................................................................................................................
352
How
It
Works
......................................................................................................................................................
352
The
Gode
.............................................................................................................................................................
354
xvii
■
CONTENTS
Usage
..................................................................................................................................................................
357
10.4
Adding
a
Managed
Object
to
Core
Data
..................................................
357
Problem
..............................................................................................................................................................
357
Solution
..............................................................................................................................................................
357
How
It
Works
......................................................................................................................................................
357
The
Code
.............................................................................................................................................................
358
Usage
..................................................................................................................................................................
361
10.5
Retrieving
Objects
from
the
Data
Store
..................................................
362
Problem
..............................................................................................................................................................
362
Solution
..............................................................................................................................................................
362
How
It
Works
......................................................................................................................................................
362
The
Code
.............................................................................................................................................................
363
Usage
..................................................................................................................................................................
367
10.6
Posting
Changes
to
the
Data
Store
.........................................................
368
Problem
..............................................................................................................................................................
368
Solution
..............................................................................................................................................................
368
How
It
Works
......................................................................................................................................................
368
The
Code
.............................................................................................................................................................
369
Usage
..................................................................................................................................................................
374
10.7
Using
One-To-One
Relationships
with
Core
Data
....................................
375
Problem
..............................................................................................................................................................
375
Solution
..............................................................................................................................................................
375
How
It
Works
......................................................................................................................................................
375
The
Code
.............................................................................................................................................................
380
Usage
..................................................................................................................................................................
384
10.8
Using
One-
To-Many
Relationships
with
Core
Data
.................................
385
Problem
..............................................................................................................................................................
385
Solution
..............................................................................................................................................................
385
How
It
Works
......................................................................................................................................................
385
The
Code
.............................................................................................................................................................
391
Usage
..................................................................................................................................................................
397
10.9
Managing
Data
Store
Versioning
............................................................
397
Problem
..............................................................................................................................................................
397
Solution
..............................................................................................................................................................
398
How
It
Works
......................................................................................................................................................
398
The
Code
.............................................................................................................................................................
401
Usage
..................................................................................................................................................................
408
Chapter
11:
Objective-C
Beyond
Mac
and
iOS
.............................................
409
11.1
Installing
GNUstep
on
Windows
..............................................................
409
Problem
..............................................................................................................................................................
409
Solution
..............................................................................................................................................................
409
xviii
CONTENTS
Usage
..................................................................................................................................................................
357
10.4
Adding
a
Managed
Object
to
Core
Data
..................................................
357
Problem
..............................................................................................................................................................
357
Solution
..............................................................................................................................................................
357
How
It
Works
......................................................................................................................................................
357
The
Code
.............................................................................................................................................................
358
Usage
..................................................................................................................................................................
361
10.5
Retrieving
Objects
from
the
Data
Store
..................................................
362
Problem
..............................................................................................................................................................
362
Solution
..............................................................................................................................................................
362
How
It
Works
......................................................................................................................................................
362
The
Code
.............................................................................................................................................................
363
Usage
..................................................................................................................................................................
367
10.6
Posting
Changes
to
the
Data
Store
.........................................................
368
Problem
..............................................................................................................................................................
368
Solution
..............................................................................................................................................................
368
How
It
Works
......................................................................................................................................................
368
The
Code
.............................................................................................................................................................
369
Usage
..................................................................................................................................................................
374
10.7
Using
One-To-One
Relationships
with
Core
Data
....................................
375
Problem
..............................................................................................................................................................
375
Solution
..............................................................................................................................................................
375
How
It
Works
......................................................................................................................................................
375
The
Code
.............................................................................................................................................................
380
Usage
..................................................................................................................................................................
384
10.8
Using
One-
To-Many
Relationships
with
Core
Data
.................................
385
Problem
..............................................................................................................................................................
385
Solution
..............................................................................................................................................................
385
How
It
Works
......................................................................................................................................................
385
The
Code
.............................................................................................................................................................
391
Usage
..................................................................................................................................................................
397
10.9
Managing
Data
Store
Versioning
............................................................
397
Problem
..............................................................................................................................................................
397
Solution
..............................................................................................................................................................
398
How
It
Works
......................................................................................................................................................
398
The
Code
.............................................................................................................................................................
401
Usage
..................................................................................................................................................................
408
Chapter
11:
Objective-C
Beyond
Mac
and
iOS
.............................................
409
11.1
Installing
GNUstep
on
Windows
..............................................................
409
Problem
..............................................................................................................................................................
409
Solution
..............................................................................................................................................................
409
xviii
CONTENTS
How
It
Works
......................................................................................................................................................
410
11.2
Objective-C
Hello
World
on
Windows
......................................................
412
Problem
..............................................................................................................................................................
412
Solution
..............................................................................................................................................................
412
How
It
Works
......................................................................................................................................................
412
The
Code
.............................................................................................................................................................
415
Usage
..................................................................................................................................................................
415
11.3
Downloading
Objective-J
for
Web
Apps
..................................................
416
Problem
..............................................................................................................................................................
416
Solution
..............................................................................................................................................................
416
How
It
Works
......................................................................................................................................................
416
Usage
..................................................................................................................................................................
417
11.4
Coding
a
Hello
World
Objective-J
Application
........................................
417
Problem
..............................................................................................................................................................
417
Solution
..............................................................................................................................................................
418
How
It
Works
......................................................................................................................................................
418
The
Code
.............................................................................................................................................................
422
Usage
..................................................................................................................................................................
423
11.5
Adding
a
Button
to
an
Objective-J
Application
.......................................
424
Problem
..............................................................................................................................................................
424
Solution
..............................................................................................................................................................
424
How
It
Works
......................................................................................................................................................
424
The
Code
.............................................................................................................................................................
426
Usage
..................................................................................................................................................................
427
Who
This
Book
Is
For
..........................................................................................................................................
xxiii
What
You
Will
Learn
............................................................................................................................................
xxiii
Downloading
the
Code
........................................................................................................................................
xxiv
Contacting
the
Author
.........................................................................................................................................
xxiv
xix
CONTENTS
How
It
Works
......................................................................................................................................................
410
11.2
Objective-C
Hello
World
on
Windows
......................................................
412
Problem
..............................................................................................................................................................
412
Solution
..............................................................................................................................................................
412
How
It
Works
......................................................................................................................................................
412
The
Code
.............................................................................................................................................................
415
Usage
..................................................................................................................................................................
415
11.3
Downloading
Objective-J
for
Web
Apps
..................................................
416
Problem
..............................................................................................................................................................
416
Solution
..............................................................................................................................................................
416
How
It
Works
......................................................................................................................................................
416
Usage
..................................................................................................................................................................
417
11.4
Coding
a
Hello
World
Objective-J
Application
........................................
417
Problem
..............................................................................................................................................................
417
Solution
..............................................................................................................................................................
418
How
It
Works
......................................................................................................................................................
418
The
Code
.............................................................................................................................................................
422
Usage
..................................................................................................................................................................
423
11.5
Adding
a
Button
to
an
Objective-J
Application
.......................................
424
Problem
..............................................................................................................................................................
424
Solution
..............................................................................................................................................................
424
How
It
Works
......................................................................................................................................................
424
The
Code
.............................................................................................................................................................
426
Usage
..................................................................................................................................................................
427
Who
This
Book
Is
For
..........................................................................................................................................
xxiii
What
You
Will
Learn
............................................................................................................................................
xxiii
Downloading
the
Code
........................................................................................................................................
xxiv
Contacting
the
Author
.........................................................................................................................................
xxiv
xix
www.allitebooks.com
剩余451页未读,继续阅读
2013-04-24 上传
2014-08-07 上传
点击了解资源详情
点击了解资源详情
2023-04-22 上传
2021-05-09 上传
2021-04-03 上传
2016-08-16 上传
115 浏览量
Tadas-Gao
- 粉丝: 190
- 资源: 390
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- javascript-carnival
- 2009中国大学创业富豪榜
- 文件加密练习.zip
- AVNCommunication8
- Wing Designer:Wing Designer 根据机翼和发动机参数计算飞机性能指标。-matlab开发
- javaScriptCardio:每日原始Javascript练习,复杂程度不一
- Drawer-Behavior-Flutter:抽屉行为是一个在抽屉上提供额外行为的库,例如,当抽屉在幻灯片上时,移动视图或缩放视图的高度
- flink 基础教程
- AirplaneManager-APCS-Project
- OrthoView:用于交互式查看 3D 体积的 GUI。-matlab开发
- 51单片机设计数码管显示秒表keil工程文件C源文件
- 图书管理系统(VB+SQL)
- powerampapi:Poweramp API
- 基于DHCP的网络配置实验文档.rar
- CIFAR-10 Dataset-数据集
- 中环绿健室内环保打造专业的品牌
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功