Swift Package Manager can't find module

纵然是瞬间 提交于 2019-12-11 09:28:38

问题


I'm trying to get familiar with Swift Package Manager. That's what I did:

    • swift package init --type executable
    • added a dependency in Package.swift
    • swift build

And everything was fine, but after I tried to import Dependency in the code xcode says: no such module.

My Package.swift looks like:

import PackageDescription

let package = Package(
    name: "todo-bot",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/zmeyc/telegram-bot-swift.git", from: "0.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(
            named: "todo-bot",
            dependencies: ["telegram-bot-swift"]),
    ]
)

And when i try to build it without xcode it goes

  • Compile Swift Module 'SwiftyJSON' (2 sources)
    • Compile Swift Module 'ScannerUtils' (2 sources)
    • Compile Swift Module 'TelegramBot' (135 sources)
    • Compile Swift Module 'todo_bot' (1 sources)

/opt/local/include/curl/system.h:399:12: note: while building module 'Darwin' imported from /opt/local/include/curl/system.h:399: # include ^ :338:9: note: in file included from :338: #import "ncurses.h" ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/ncurses.h:141:10: note: in file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/ncurses.h:141: #include ^ /opt/local/include/unctrl.h:60:63: error: unknown type name 'SCREEN' NCURSES_EXPORT(NCURSES_CONST char ) NCURSES_SP_NAME(unctrl) (SCREEN, chtype); ^ /opt/local/include/curl/system.h:399:12: note: while building module 'Darwin' imported from /opt/local/include/curl/system.h:399: '#' include ^


回答1:


I have noticed this issue creep up on me today too. I followed the following steps to get rid of this error.

  1. Close Xcode application
  2. Delete the .xcodeproj file
  3. Regenerate the packages again by running swift package generate-xcodeproj.

The next time you open the Xcode project the packages will be installed correctly and you won't have any build issues. Not sure this is going to help someone but I hope it does :)



来源:https://stackoverflow.com/questions/49119348/swift-package-manager-cant-find-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!