什么是Swift Compiler-Xcode 6 Building Settings中的搜索路径导入路径? [英] What is Swift Compiler - Search Paths Import Paths in Xcode 6 Building Settings?

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

问题描述

在Xcode 6(测试版)中,有Swift编译器-搜索路径,导入路径.它是做什么的?

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 *
}

  • 转到构建设置",将Swift Compiler - Search Paths> Import Paths设置为放置module.map文件的目录.然后,即使在Swift REPL中,您也可以使用import tidy并利用HTML Tidy库的有用API.

  • 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-Xcode 6 Building Settings中的搜索路径导入路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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