Giter Club home page Giter Club logo

swift-framework-c-library-example's Introduction

Swift Progress Bar Framework

This is the code example from my blog article: Wrapping a C Library in a Swift Framework. To see the creation of this project from the beginning to end, feel free to read the post!

If you like this, feel free to check out my site!

Motivation

Bridging Headers are the recommended way of including C, C++, and Objective-C code in your Swift projects. However, the compiler does not allow you do this for Framework targets, which is a problem if you wish to create a Framework that wraps a C library.

This repository is an example of how to create a Swift framework that is able to call out to a C library without using Bridging Headers. Instead, it uses Clang Module Mapping.

Example Framework

The Progressbar framework is exported by this example project. It includes one class: Progressbar.

The Progressbar class has one initializer that takes two required parameters: text and max, the text to display and the maximum value of the progress bar.

Each Progressbar instance responds to two methods: increment and finish. increment bumps up (and animates) the progress bar by one unit. finish completes the bar and finishes drawing.

Example Framework Usage

The Xcode project contains an Xcode Playground demonstrating usage of the module. You should see a progress bar animating over the course of 30 seconds once you open this file. If you don't see it, press โŒ˜-Shift-Y to ensure that the Console window is showing.

Dependencies/Thanks

progressbar is the C library that is wrapped in this example project. The source is included with this git repository. Thanks to the original author for providing a simple library to wrap!

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.