05 ธันวาคม 2561

create swift framework and include some dependency using swift package manager

in the example, i gonna create swift framework and use library https://github.com/vapor/jwt

1. create new folder, e.g., testJwt
$ mkdir testJwt

2. goto the folder
$ cd testJwt

3. init package
$ swift package init

4. update Package.swift
$ vi Package.swift

update file like this

dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/vapor/jwt.git", from: "3.0.0")
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "testJwt",
            dependencies: ["JWT"]),
        .testTarget(
            name: "testJwtTests",
            dependencies: ["testJwt"]),

    ]


5. install package dependencies
$ swift package update

6. generate xcode project
$ swift package generate-xcodeproj

7. build project
$ swift build

8. then you can call JWT from your framework code by adding import JWT at the top of the swift file


Note:

if you found the error like error: 'openssl/conf.h' file not found

try to install commands below

$ brew install openssl
$ brew upgrade openssl
$ brew install libressl

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

บทความยอดนิยม (ล่าสุด)

บทความยอดนิยม (All Time)