我正在开始一个新的Cocoa Swift项目,通过以下Podfile将PubNub SDK纳入其中:
target 'myProject' do
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
pod 'PubNub', '~>4.0'
pod 'Alamofire', '~> 1.3'
end
target 'myProjectTests' do
end
在我的自动生成的桥接头文件中,我有PubNub的导入:
#import <PubNub/PubNub.h>
我的AppDelegate.swift文件:
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var client:PubNub?
func applicationDidFinishLaunching(aNotification: NSNotification) {
let config = PNConfiguration( publishKey: "Your_Pub_Key", subscribeKey: "Your_Sub_Key")
client = PubNub.clientWithConfiguration(config)
client?.addListener(self)
client?.subscribeToChannels(["Your_Channel"], withPresence: false)
client?.publish("Swift + PubNub!", toChannel: "demo", compressed: false, withCompletion: nil) }
func client(client: PubNub!, didReceiveMessage message: PNMessageResult!) {
println(message)
}
func applicationWillTerminate(aNotification: NSNotification) {
// Insert code here to tear down your application
}
}
由于使用了未声明的类型PubNub,项目无法构建。我已经检查了构建设置,Swift编译器-代码生成部分显示它指向目标的桥接头文件(自动填充)。
使用Xcode 6.4和pods版本0.38.2