Swiftpack.co - Package - ApolloZhu/swift_qrcodejs

QRCodeSwift (swift_qrcodejs)

Latest Release MIT License Swift 5.0+ Compatible with All Platforms

Documentation Code Coverage CocoaPods Compatible Swift Package Manager Compatible Carthage Compatible

Cross-platform QRCode generator written in pure Swift, aiming to solve the awkward situation that there's no CIFilter for QRCode generation on Apple Watches.


More details in the Official Guide, but in general:

  1. Select in the menu bar of Xcode: File > Swift Packages > Add Package Dependency
  2. Enter https://github.com/ApolloZhu/swift_qrcodejs.git
  3. Next, specify the version resolving rule as "Up to Next Major"
  4. Finish with choosing QRCodeSwift library and add it to your app target.
dependencies: [
    .package(url: "https://github.com/ApolloZhu/swift_qrcodejs.git", from: "2.2.2"),

... then add QRCodeSwift module/target from package swift_qrcodejs as your dependency.

pod 'swift_qrcodejs', '~> 2.2.2'

I assume you know what you are doing (because I don't), but you probably need something like this:

github "ApolloZhu/swift_qrcodejs" ~> 2.2.2

Note that Carthage doesn't work with Xcode 12 (but here's a workaround).

Add all the .swift files from the Sources folder into your project.


import QRCodeSwift

guard let qrCode = try? QRCode("Hello World!") else {
    fatalError("Failed to generate QRCode")
print(qrCode.toString(filledWith: "##", patchedWith: "  "))

For more, checkout the documentation.

Example Projects


MIT License. Modified based on qrcodejs. See LICENSE and each individual file header for more information.


Stars: 24


Used By

Total: 0


QRCodeSwift / swift_qrcodejs 2.2.2 -



  • Instructions on how to integrate through Swift Package Manager using Xcode UI.

I highly recommend using SPM instead of Carthage. Makes life so much easier.

QRCodeSwift / swift_qrcodejs 2.2.1 -

CI only release

QRCodeSwift / swift_qrcodejs 2.2.0 -


  • Renamed module name from swift_qrcodejs to QRCodeSwift to comply with C standard:
- import swift_qrcodejs
+ import QRCodeSwift
  • QRCodeSwiftCLI (formerly swift_qrcodejs-cli) is now a separate package.


  • Building with Carthage now works on all platforms supported.


  • iOS 8 is no longer supported through CocoaPods (in sync with Xcode 12)

swift_qrcodejs 2.1.0 -


  • QRCode can now be directly initialized with Data in addition to String + encoding


  • QRCode no longer has text property. Should you think it's necessary for QRCode to retain its content, open a new issue for discussions.

swift_qrcodejs 2.0.0 - try, try?, try! -


  • QRCode constructor now throws errors instead of returning nil.

    For simple migration, use try?:

    let qrCode = try? QRCode("Hello World!")

    To handle error:

    do {
       let qrCode = try QRCode("Hello World")
       // use QRCode here
    } catch let error as QRCodeError {
       // figure out what went wrong
    } catch {
       // should not happen, but required by compiler
  • Now use GitHub Action for continuous integration

swift_qrcodejs 1.2.0 - Coding? Encoding! -

Encoding text with non-utf8 encoding should now be fully supported thanks to @joaodforce (#10).

swift_qrcodejs 1.1.4 -

Bug fixes and performance improvements.

swift_qrcodejs 1.1.3 -

Update Swift version from 4.2 to 5.0 in config files. Nothing else changed.

swift_qrcodejs 1.1.2 -

What's New

List all supported Swift versions in podspec by @chrisballinger (#6). Requires CocoaPods 1.7.5 or a newer version.

swift_qrcodejs 1.1.1 - Just Swift 5 -

swift-version and podspec remains to be Swift 4.2 to maximize compatibility

swift_qrcodejs 1.1.0 - What is UTF8? -

What's New

Added option to choose text encoding for QRCode data by @joaodforce (#5)

Author's Perspective

Some other parts of this library still assumes UTF-8, so I'm expecting to see some test cases, crash reports, and/or other failures to come in, based on my limited knowledge of QRCode. Please open issues and/or pull requests when you encounter unexpected results.

swift_qrcodejs 1.0.1 - Overflown? Not any more -

What's New

Fix hanging when string exceeds the maximum capable length to convert (#4) Fix crashes when UTF-8 length of string is in range [195, 220] (#4)

swift_qrcodejs 1.0.0 - Released! -

What's New

See https://apollozhu.github.io/swift_qrcodejs/ for documentation and