The community forums are in BETA and closed to the public.

PubNub and ios/swift

Hi all,

I have used "pub nub" in the past, particularly the Javascript API, which I have found to be amazingly easy and powerful. I am now working on moving some of that functionality over to an iOS client, and I am a bit disappointed in lack of maintenance in the software for iOS/Cocoa. It looks like the library was last updated in 2012, and it no longer compiles "out of the box" on the latest Xcode (6.x).

Also, has there been any announcement regarding supporting the new Apple language Swift? While in BETA right now, it will be released in the near future, and most Apple developers are moving towards it rather quickly. It would be wonderful if a new version of the SDK was released that supported Swift.

Just my 2 cents

Not sure where you are seeing the "old" updates but here is the latest.

There has been extensive hardening of the iOS SDK in the past few weeks. There is some Swift integration docs on the README of the github but no actual Swift SDK at this time.

Thanks, I was using a slightly older version. I will investigate this version. Other companies (i.e. Parse) are keeping their SDK in Objective-C, but providing a bridge-header file which allows for Swift programs to be written. They are also providing newer documentation with both Objective-C/Swift code, which is a nice touch.

After following the on-line instructions, and using the latest SDK, it was not too difficult to get the basic functionality working in Swift. Here is the AppDelegate:

@UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, PNDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.

    // set delegate

    // set the pubnub keys to demo

    // connect to PubNub

    // subscribe to a channel
    let myChannel: PNChannel = PNChannel.channelWithName("a") as! PNChannel

    // publish on the channel
    PubNub.sendMessage("Hello from PubNub ios!", toChannel: myChannel)

    // unsubscribe from the channel

    // disconnect from PubNub

    return true

func pubnubClient(client: PubNub, didReceiveMessage message: PNMessage) -> Void{
    println("PubNub client received message: \(message.message)")

Login or Signup to post a comment