Chilkat iOS — Compiling & Linking in Xcode

How to add the Chilkat iOS static library (or XCFramework) to your Xcode project and link it successfully — for Objective-C, Swift, and C / C++.

Jump to: Before you start Two approaches Add a static library Add an XCFramework Linker flags Swift Using & unlocking Memory & ARC More notes

Before you start

The download contains a separate static library for each architecture slice. Before linking, combine the slices you target into a universal static library or an XCFramework, as described on the dedicated page:

Device vs simulator A traditional static library must not mix device and simulator slices. Use the device library when building for a physical iPhone/iPad and the simulator library when building for the iOS Simulator — or use an XCFramework, which holds both and lets Xcode choose automatically.

For reference, the slices in the download are:

  • Device: lib/arm64, lib/arm64e, lib/armv7, lib/armv7s
  • Simulator: lib/arm64-sim (Apple Silicon), lib/x86_64 (Intel)

Two ways to integrate Chilkat

Static library (.a)

Link the universal libchilkatIos.a directly. You manage the header search path and choose the device or simulator library per build.

Recommended

XCFramework

Add Chilkat.xcframework once. It bundles the device and simulator libraries plus headers, and Xcode selects the correct binary automatically.

Both approaches still require the linker flags below. Steps for each follow.


Adding a static library (.a)

  1. Add the header search path

    In Build Settings → Header Search Paths, add the directory containing the Chilkat headers:

    • include — for Objective-C and Swift (the Cko* classes)
    • cpp_include — for C / C++ (the Ck* classes)
  2. Link the library

    Go to Build Phases → Link Binary With Libraries, click +, then Add Other…, and select the universal libchilkatIos.a you built. (Xcode adds its folder to Library Search Paths automatically.)

  3. Add the linker flags

    Add the required flags to Other Linker Flags — see Linker flags below.

  4. Select the matching library for your target

    Link the device library for device builds and the simulator library for simulator builds. (An XCFramework avoids having to switch.)


Adding an XCFramework

  1. Drag it into your project

    Drag Chilkat.xcframework into the Xcode Project Navigator, or add it under General → Frameworks, Libraries, and Embedded Content with the + button.

  2. Set "Do Not Embed"

    Because Chilkat is a static library, set the embed option to Do Not Embed. (Static code is linked into your app binary; there is nothing to embed as a separate bundle.)

  3. Headers come with it

    The XCFramework includes the Chilkat headers, so a separate Header Search Path is normally not needed. Import headers in your code as shown under Using & unlocking.

  4. Add the linker flags

    Add the required flags to Other Linker Flags — see below.


Other Linker Flags

Chilkat depends on a few system libraries. In Build Settings → Other Linker Flags, add:

-lresolv -lpthread -lc++
  • -lresolv — the DNS resolver library (used for networking).
  • -lpthread — POSIX threads.
  • -lc++ — the LLVM C++ standard library.

Swift projects: add a bridging header

Chilkat's iOS interface is Objective-C, so Swift code reaches it through a bridging header.

  1. Create the bridging header

    Add a header named YourProject-Bridging-Header.h and import the Chilkat Cko classes your app uses:

    #import <Foundation/NSObject.h>
    
    #import "chilkat-ios/include/CkoGlobal.h"
    #import "chilkat-ios/include/CkoJsonObject.h"
    #import "chilkat-ios/include/CkoHttp.h"
    // Import each Cko*.h header your app uses. The path depends on
    // where you extracted the Chilkat headers.
  2. Point Xcode at it

    Set Build Settings → Objective-C Bridging Header to the path of that file. Swift can then call the Chilkat classes directly.

More on Swift For details on calling Chilkat from Swift — how Objective-C names map to Swift, the trial/license unlock call, and common problems — see Using Chilkat from Swift on iOS.

Using & unlocking Chilkat

Chilkat runs as a fully functional 30-day trial out of the box. Unlock it once at startup by calling UnlockBundle on a CkoGlobal object — pass any non-empty string for the trial, or your license code after purchase.

Objective-C
#import "CkoGlobal.h"
#import "CkoJsonObject.h"

// Call once, at application startup.
CkoGlobal *glob = [[CkoGlobal alloc] init];
BOOL success = [glob UnlockBundle: @"Anything for 30-day trial"];
if (!success) {
    NSLog(@"%@", glob.LastErrorText);
    return;
}

// Use any Chilkat class.
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"author.name" value: @"Chilkat"];
NSLog(@"%@", [json Emit]);

In C++, the equivalent is CkGlobal glob; glob.UnlockBundle("..."); using the cpp_include headers.

Reference & examples Full API reference is in the Chilkat documentation, and runnable samples are at Chilkat Example Code (Objective-C, Swift, and C++).

Memory management & ARC

All objects returned by Chilkat methods — including NSString, NSNumber, NSData, NSMutableData, NSDate, and Cko Chilkat objects — are autoreleased. Your application does not need to release them.

The Chilkat library works with ARC (Automatic Reference Counting) enabled.

Background threads If you call Chilkat from a background thread, see this note on the Chilkat blog about Auto-release Pools and Background Threads — a thread you create needs its own autorelease pool.

Additional notes

The static library is only needed at link time

A static library (.a), and a static XCFramework, are used only when building your app. At link time the referenced Chilkat code is copied directly into your application's executable. You do not ship or install libchilkatIos.a (or Chilkat.xcframework) with your app, and there is nothing for the end user to install — this is also why an XCFramework is added with Do Not Embed.

About the size of the static library

A static linker compiles into your executable only the library code that is directly or indirectly referenced. Your application binary is the same size regardless of how the library is arranged — as one large library or several smaller ones — so the size of libchilkatIos.a on disk does not reflect how much is added to your app.

Bitcode

Bitcode has been removed from Xcode (deprecated in Xcode 14) and is no longer required or accepted by the App Store. If you use an older Xcode that still has the setting, set Enable Bitcode to No.

 

← Back to Chilkat iOS Library Downloads