将 Objective-C 框架连接到 Swift iOS 8 应用程序(解析框架) [英] Connect Objective-C framework to Swift iOS 8 app (Parse framework)

查看:24
本文介绍了将 Objective-C 框架连接到 Swift iOS 8 应用程序(解析框架)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有 Swift 编程语言的 Objective-C 框架进行 iOS 8 开发.这是导入的特定情况,但一般问题是:

I am trying to use an Objective-C framework with the Swift programming language for iOS 8 development. This is a specific case of an import but the general problem is:

你如何将一个 Objective-C 框架导入 swift 并让导入被识别?

我正在尝试使用 iOS 8 和 Xcode 6 beta 将 Parse 框架集成到一个 swift 应用程序中.

I am trying to integrate the Parse framework into a swift application using the iOS 8 and Xcode 6 betas.

这是Objective-C中Parse框架集成的技术:

Here is the technique for Parse framework integration in Objective-C:

https://www.parse.com/apps/快速入门#social/mobile/ios/native/existing

我已将 Parse 框架作为压缩档案下载、解压缩并将其导入 Xcode 6,没有任何问题.在我的应用程序中,它显示为名称为 Parse.framework 的格式正确的框架.

I have downloaded the Parse framework as a compressed archive, extracted it, and imported it into Xcode 6 without any problems. Within my application it appears as a properly formatted framework under the name Parse.framework.

我目前的思路是修改项目根目录下的AppDelegate.swift文件.这是没有修改的当前文件(由 Xcode 在 swift 项目创建时自动生成):

My current thought process is to modify the AppDelegate.swift file in the root directory of my project. Here is the current file without modifications (automatically generated by Xcode upon swift project creation):

https://gist.github.com/fconcklin/e8ef7d8b056105a04161

我尝试通过在 import UIKit 行下方添加行 import Parse 来导入 parse.但是,Xcode 发出警告,指出找不到此类模块并且构建失败.

I have tried to import parse by adding the line import Parse below the line import UIKit. However, Xcode issues a warning that there is no such module found and the build fails.

我还尝试创建一个文件 ${PROJ_NAME_HERE}-Bridging-Header.h,其中包含使用 import <Parse/Parse.h> 导入的 Parse 的 Objective-C 导入代码>.该行不会引发错误,但似乎最终没有任何区别.

I also tried creating a file ${PROJ_NAME_HERE}-Bridging-Header.h that contains the Objective-C import of Parse using import <Parse/Parse.h>. This line doesn't throw an error but appears to ultimately make no difference.

推荐答案

添加桥接头的傻瓜式"方法如下:

A "Fool Proof" way of adding a bridging header is as follows:

如果您有一个 Swift 项目,请将一个新的 Objective-C 文件 添加到您的项目中,Xcode 将提示您是否要使用桥接头配置您的项目.按是.

If you have a Swift project, add a new Objective-C File to your project and Xcode will prompt if you want to configure your project with a bridging header. Press yes.

如果您有一个 Objective-C 项目,请向其中添加一个新的 Swift 文件,您将得到相同的提示.按是.

If you have a Objective-C project, add a new Swift File to it and you will get the same prompt. Press yes.

获得桥接头后,您可以根据需要删除刚刚添加的文件.

After you get the bridging header, you can delete the file you just added if you want to.

这篇关于将 Objective-C 框架连接到 Swift iOS 8 应用程序(解析框架)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆