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.
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
-
Add the header search path
In Build Settings → Header Search Paths, add the Chilkat
includedirectory (the folder containing theCko*.hheaders). -
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. -
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
#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]);
Using Chilkat from Swift
Chilkat's interface is Objective-C, so Swift reaches it through a bridging header:
-
Create a bridging header
Add
YourProject-Bridging-Header.hand import the ChilkatCkoclasses you use:#import <Foundation/NSObject.h> #import "CkoGlobal.h" #import "CkoJsonObject.h"
-
Point Xcode at it
Set Build Settings → Objective-C Bridging Header to the path of that file.
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.
@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: