什么是 Swift Compiler - Search Paths Import Paths in Xcode 6 Building Settings? [英] What is Swift Compiler - Search Paths Import Paths in Xcode 6 Building Settings?

查看:21
本文介绍了什么是 Swift Compiler - Search Paths Import Paths in Xcode 6 Building Settings?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Xcode 6 (Beta) 中,有 Swift Compiler - Search Paths, Import Paths.它有什么作用?

In Xcode 6 (Beta), there is Swift Compiler - Search Paths, Import Paths. What does it do?

推荐答案

只是为了分享我在连接点的日子里发现的东西.简短回答,导入搜索路径指定 Swift 查找和导入模块的位置.

Just to share what I have discovered during days of connecting dots. Short answer, Import Search Path specifies where Swift finds and imports modules.

什么是模块?模块通过用更健壮、更高效的语义模型替换文本预处理器包含模型来改进对软件库 API 的访问.从用户的角度来看,代码看起来只是略有不同,因为我们使用了导入声明而不是像这样的 #include 预处理器指令:

What are modules? Modules improve access to the API of software libraries by replacing the textual preprocessor inclusion model with a more robust, more efficient semantic model. From the user’s perspective, the code looks only slightly different, because one uses an import declaration rather than a #include preprocessor directive like this:

import std.io

Apple 于 2012 年 11 月在 LLVM DevMeeting 上首次宣布.您仍然可以在这里找到 Doug Gregor 的演讲(视频PDF).在 WWDC 2013 上,语义导入与 iOS 7 一起被引入,@import 就是为了它.因此,该模块成为新语言 Swift 的一部分是决定性的.可以在此处找到模块文档.

It was first announced in Nov 2012 by Apple at LLVM DevMeeting. You can still find the Doug Gregor’s talk here (Video and PDF). At WWDC 2013, Semantic Import was introduced on along with iOS 7, the @import was just for it. So it was determinant that module to be part of new language Swift. Documentation of modules can be found here.

为了体验一下,以下是使用 HTML Tidy 库模块创建示例应用项目的步骤.

To have a taste, below are steps to create an example app project with HTML Tidy library module.

  • 在 Xcode 6 中创建一个 Swift 项目(OS X 或 iOS)

  • Create a Swift project (OS X or iOS) in Xcode 6

创建一个 module.map 文件,并将其放在一个目录中.例如./Users/vladof/module/

Create a module.map file, and place it in a directory. E.g. /Users/vladof/module/

module tidy [system] {
    header "/usr/include/tidy/tidy.h"
    header "/usr/include/tidy/buffio.h"
    link "tidy"
    export *
}

  • Go Build Settings,将Swift Compiler - Search Paths > Import Paths 设置为您放置module.map 的目录文件在. /Users/vladof/module 在我的情况下.然后您可以使用 import tidy 并利用 HTML Tidy 库的有用 API,即使在 Swift REPL 中也是如此.

  • Go Build Settings, set Swift Compiler - Search Paths > Import Paths to the directory that you put the module.map file in. /Users/vladof/module in my case. Then you can use import tidy and leverage useful APIs of HTML Tidy library, even in Swift REPL.

    导入

    import tidy
    

  • 示例代码

  • Example code

    var input: CString = "<node>upper case node</node>"
    var tdoc: TidyDoc = tidyCreate() // Initialize "document"
    var rc: Int32 = -1
    var ok = tidyOptSetBool(tdoc, TidyUpperCaseTags, yes) // Convert tags to upper cases
    ok = tidyOptSetBool(tdoc, TidyXmlTags, yes) // Convert to XML
    
    if ok.value == 1 {
        rc = tidyParseString(tdoc, input) // Parse the input
        if rc >= 0 {
            rc = tidyCleanAndRepair(tdoc) // Tidy it up
        }
        if rc >= 0 {
            rc = tidySaveStdout(tdoc) // Pretty print to console
        }
    }
    

  • 打印

  • Print

    <NODE>upper case node</NODE>
    

  • 我也尝试过 curl 模块.事实上,我测试时没有导入一些 API,例如curl_easy_setopt(),希望他们在不久的将来赶上.但我很肯定这为 Swift 开发者打开了一扇门.

    Also I have experimented with curl module. In fact some APIs are not imported as I test, e.g. curl_easy_setopt(), let’s hope they catch up in near future. But I am positive this opens a door for Swift developers.

    这篇关于什么是 Swift Compiler - Search Paths Import Paths in Xcode 6 Building Settings?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆