Chilkat for macOS — Compiling, Linking & Using in Xcode

How to add the Chilkat macOS static library to your Xcode project and use it from Objective-C or Swift. This page covers a macOS (Cocoa) app or command-line tool; for iOS, see the iOS guide.

Get the library first Download the macOS Objective-C library from Chilkat macOS Objective-C Downloads. It contains a single universal static library (lib/libchilkatObjc.a, for both Apple Silicon and Intel) and the include directory of Objective-C headers.

Jump to: Project setup .mm file extension Using & unlocking Swift Memory & ARC XCFramework?

Project setup

  1. Add the header search path

    In Build Settings → Header Search Paths, add the Chilkat include directory (the folder containing the Cko*.h headers).

  2. Link the static library

    Go to Build Phases → Link Binary With Libraries, click +, then Add Other…, and select libchilkatObjc.a. The library is already universal (arm64 + x86_64), so there is nothing to combine.

  3. Add the linker flags

    In Build Settings → Other Linker Flags, add:

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

Name source files that use Chilkat with the .mm extension

Common first-time mistake Any application source file that #imports a Chilkat header must be named with the .mm extension (Objective-C++), not .m. For example, rename ViewController.m to ViewController.mm. Using .m typically produces confusing compile errors.

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.

#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]);
Reference & examples Full API reference is in the Chilkat documentation, and runnable samples are at Objective-C and Swift example code.

Using Chilkat from Swift

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

  1. Create a bridging header

    Add YourProject-Bridging-Header.h and import the Chilkat Cko classes you use:

    #import <Foundation/NSObject.h>
    #import "CkoGlobal.h"
    #import "CkoJsonObject.h"
  2. Point Xcode at it

    Set Build Settings → Objective-C Bridging Header to the path of that file.

Swift renames Objective-C symbols (it lower-cases the first letter of methods/properties and labels the first argument). For the details and a troubleshooting list, see Using Chilkat from Swift — the Swift-interop guidance there applies to macOS as well as iOS.

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. Chilkat works with ARC enabled.

Background threads If you call Chilkat from a background thread you create, wrap the work in an @autoreleasepool block. See Auto-release Pools and Background Threads.

Do you need an XCFramework?

For a macOS-only app, no. The macOS download is already a single universal static library (arm64 + x86_64). macOS has just one platform variant, so there is nothing for an XCFramework to disambiguate — linking libchilkatObjc.a directly is simpler and sufficient.

An XCFramework is worth using when you need a single package that spans multiple platforms or variants — for example a library that must serve both iOS device and iOS Simulator builds, or one binary shared across macOS and iOS targets. In those cases Xcode automatically selects the correct slice from the XCFramework. If you want to wrap the macOS static library into an XCFramework for a uniform distribution format, the xcodebuild -create-xcframework mechanics are described here:


← Back to Chilkat macOS Objective-C Library Downloads