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

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

by Matt Neuburg
January 2017
Intermediate to advanced
552 pages
9h 43m
Chinese
China Machine Press
Content preview from iOS 编程基础:Swift、Xcode 和Cocoa 入门指南
314
6
模块是精巧且便捷的,不过有时还需要手工链接到框架上。比如,假设你想在界面
中使用
MKMapView
Map Kit View
)。你可以在
.storyboard
.xib
文件中配置,
不过当构建和运行应用时,应用会崩溃,消息是“
Could not instantiate class named
MKMapView.
”。原因在于
nib
在加载时会发现它包含了一个
MKMapView
,但却不知
MKMapView
是什么。
MKMapView
定义在
MapKit
框架中,但
nib
并不知道这一点。
在代码顶部加上
import MapKit
也无法解决这个问题;如果代码想要使用
MKMapView
你就需要这么做,不过这却没办法在
nib
加载时让其知道何为
MKMapView
。解决办法
就是手工链接到
MapKit
框架:
1.
编辑目标,查看构建阶段窗格。
2.
Link Binary With Libraries
下单击
+
按钮。
3.
这时会出现一个可用框架列表(还有一些动态库)。向下滚动到
MapKit.
framework
,将其选中并单击
Add
这可以解决问题:应用现在可以构建并运行了。
你还可以创建自己的框架并作为项目的一部分。框架是个模块,因此也有助于结构化你
的代码,正如第
5
章介绍
Swift
隐私性时所述。要想创建新的框架:
1.
编辑目标并选择
Editor
Add Target
2.
在对话框左侧,
iOS
下,选择
Framework & Library
;在右侧,选择
Cocoa Touch
Framework ...
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

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
Objective-C for Absolute Beginners: iPhone, iPad and Mac Programming Made Easy

Objective-C for Absolute Beginners: iPhone, iPad and Mac Programming Made Easy

Stefan Kaczmarek, Brad Lees, Gary Bennett, Mitch Fisher

Publisher Resources

ISBN: 9787111556350