Giter Site home page Giter Site logo

testchilkatswift's Introduction

TestChilkatSwift

Demonstrate adding Chilkat to a MacOSX Swift Project, just for the sake of compiling and linking successfully.

The steps to add Chilkat to your Swift project are:

1) Download the Chilkat Cocoa Library for MacOSX or iOS

For MacOSX applications, download the Chilkat Cocoa library for MacOSX.

For iOS applications, download the Chilkat iOS Objective-C Libs w/ bitcode enabled and libstdc++

2) Add an Objective-C Bridging Header to your project.

Create a .h header file named YourProject-Bridging-Header.h, and insert the following:

#import <Foundation/NSObject.h>

#import "chilkat-9.5.0-macosx-objc/include/CkoJsonObject.h"
#import "chilkat-9.5.0-macosx-objc/include/CkoXml.h"
#import "chilkat-9.5.0-macosx-objc/include/CkoZip.h"

// The import path to each Cko*.h header depends on where you downloaded/extracted the Chilkat lib.
// Import the Chilkat "Cko" classes used by your application...

3) Set the Swift Bridging Header in your Project's Build Settings.

For example:
Swift Bridging Header

4) Add Chilkat Code

We added the following Chilkat code to AppDelegate.swift. It does nothing and was only inserted to test compiling and linking. The purpose of this project is simply to get a clean compile and build, not to run it..

    // Add code that uses Chilkat so we can test compiling/linking...
    //
    func chilkatCode() {
        let json = CkoJsonObject()!
        
        var success: Bool
        
        // The only reason for failure in the following lines of code would be an out-of-memory condition,
        // which isn't going to happen...
        
        //  An index value of -1 is used to append at the end.
        success = json.addString(at: -1, name: "Title", value: "Pan's Labyrinth")
        if (success) {
            success = json.addString(at: -1, name: "Director", value: "Guillermo del Toro")
        }
        if (success) {
            success = json.addString(at: -1, name: "Original_Title", value: "El laberinto del fauno")
        }
        if (success) {
            success = json.addInt(at: -1, name: "Year_Released", value: 2006)
        }
        
        json.emitCompact = false
        //print("\(json.emit()!)")
        
    }

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application
        // test creating and using a Chilkat object.
        chilkatCode();
        
    }

5) Add the Chilkat Static Library (.a)

Go to your project's Build Phases (the tab located just to the right of Build Settings) and add the libChilkatCocoa.a (for MacOSX) or libChilkatIos.a (for iOS).

Do this by expanding the Link Binary with Libraries section, then click on "+" to add items, then click on the Add Other button. Navigate to the directory where the Chilkat static lib (.a) located and add it.

Build Phases

6) Add -lresolv -lpthread -lstdc++ to Other Linker Flags

In Build Settings, Add -lresolv -lpthread -lstdc++ to Other Linker Flags.

Other Linker Flags

7 Final Notes

That should be everything. (If not, please let us know by sending email to [email protected])

Important Chilkat provides documentation for both Swift 2 and Swift 3 / Swift 4. When Objective-C is used in Swift version 2, the imported methods and properties (via the Bridging Header) have names that are unmodified.

However.. when using Swift version 3 or Swift version 4, the method and property names imported from Objective-C are renamed. The 1st letter of each method and property is changed to lowercase, and some method names may have been renamed. Chilkat provides separate reference documentation and examples for Swift 2 and Swift 3/4. Make sure you are aware of which documentaiton / examples you are viewing.

testchilkatswift's People

Contributors

chilkatsoft avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.