Swift 2和Linux / OS X的区别

时间:2022-07-12 02:38:38

I'm trying to port some basic app from OS X to Linux but it seems that even basic stuff is missing on Linux platform. Is there some documentation what is missing ?? Here is example:

我正在尝试将一些基本的应用程序从OS X移植到Linux,但似乎Linux平台上缺少基本的东西。有一些文件缺少什么?这是一个例子:

exmcast.swift:7:20: error: value of type 'String' has no member 'stringByReplacingOccurrencesOfString'
let name: String = address.stringByReplacingOccurrencesOfString(".", withString: "_")

This simple code works on OS X. On Linux - you see results. It's very hard to port anything when there is no basic info what is missing. And it looks like even basic stuff is missing..

这个简单的代码适用于OS X.在Linux上 - 你会看到结果。当没有基本信息丢失时,很难移植任何东西。它看起来甚至缺少基本的东西..

3 个解决方案

#1


5  

Swift 3 will be released in fall 2016.

Swift 3将于2016年秋季发布。

The recently open-sourced Swift and the Linux port are work in progress:

最近开源的Swift和Linux端口正在进行中:

The port is still a work in progress but we’re happy to say that it is usable today for experimentation.

该港口仍在进行中,但我们很高兴地说它现在可用于实验。

You can go to Swift.org and github.com/apple and enjoy the fantastic work.

你可以去Swift.org和github.com/apple,享受梦幻般的工作。

When you find something not yet implemented, you can file a bug and/or help implement the feature.

当您发现尚未实现的内容时,您可以提交错误和/或帮助实现该功能。

New versions of the open source Swift will be posted regularly on Swift.org.

新版本的开源Swift将定期发布在Swift.org上。

#2


3  

The method you are trying to call is actually part of NSString. String is bridged behind the scenes to NSString and that is why you are able to use that method on OS X. NSString is part of the Foundation framework, and Foundation is not totally implemented for Linux. You can check the status of the various parts of Foundation here: Foundation Status. NSString is currently only partially implemented.

您尝试调用的方法实际上是NSString的一部分。字符串在幕后桥接到NSString,这就是为什么你能够在OS X上使用该方法的原因.NSString是Foundation框架的一部分,而Foundation并不是完全为Linux实现的。您可以在此处查看Foundation的各个部分的状态:Foundation Status。 NSString目前仅部分实现。

#3


0  

On OSX you still need to import Foundation

在OSX上,您仍然需要导入Foundation

You are free to use pure Swift solution, in your case

在您的情况下,您可以*使用纯Swift解决方案

    let str = "alfa.beta"
// (1)
    let str1 = str.characters.map {
        $0 == "." ? "_": $0
    }.reduce("") { (str, c) -> String in
        str + String(c)
    }
// (2)
    let str2 = String(str.characters.split(".").joinWithSeparator(["_"]))
    print(str,str1,str2) // alfa.beta alfa_beta alfa_beta

for something more advanced, you have powerful functions

对于更高级的东西,你有强大的功能

mutating func replaceRange<C : CollectionType where C.Generator.Element == Character>(subRange: Range<Index>, with newElements: C)

or

mutating func replaceRange(subRange: Range<Index>, with newElements: String)

#1


5  

Swift 3 will be released in fall 2016.

Swift 3将于2016年秋季发布。

The recently open-sourced Swift and the Linux port are work in progress:

最近开源的Swift和Linux端口正在进行中:

The port is still a work in progress but we’re happy to say that it is usable today for experimentation.

该港口仍在进行中,但我们很高兴地说它现在可用于实验。

You can go to Swift.org and github.com/apple and enjoy the fantastic work.

你可以去Swift.org和github.com/apple,享受梦幻般的工作。

When you find something not yet implemented, you can file a bug and/or help implement the feature.

当您发现尚未实现的内容时,您可以提交错误和/或帮助实现该功能。

New versions of the open source Swift will be posted regularly on Swift.org.

新版本的开源Swift将定期发布在Swift.org上。

#2


3  

The method you are trying to call is actually part of NSString. String is bridged behind the scenes to NSString and that is why you are able to use that method on OS X. NSString is part of the Foundation framework, and Foundation is not totally implemented for Linux. You can check the status of the various parts of Foundation here: Foundation Status. NSString is currently only partially implemented.

您尝试调用的方法实际上是NSString的一部分。字符串在幕后桥接到NSString,这就是为什么你能够在OS X上使用该方法的原因.NSString是Foundation框架的一部分,而Foundation并不是完全为Linux实现的。您可以在此处查看Foundation的各个部分的状态:Foundation Status。 NSString目前仅部分实现。

#3


0  

On OSX you still need to import Foundation

在OSX上,您仍然需要导入Foundation

You are free to use pure Swift solution, in your case

在您的情况下,您可以*使用纯Swift解决方案

    let str = "alfa.beta"
// (1)
    let str1 = str.characters.map {
        $0 == "." ? "_": $0
    }.reduce("") { (str, c) -> String in
        str + String(c)
    }
// (2)
    let str2 = String(str.characters.split(".").joinWithSeparator(["_"]))
    print(str,str1,str2) // alfa.beta alfa_beta alfa_beta

for something more advanced, you have powerful functions

对于更高级的东西,你有强大的功能

mutating func replaceRange<C : CollectionType where C.Generator.Element == Character>(subRange: Range<Index>, with newElements: C)

or

mutating func replaceRange(subRange: Range<Index>, with newElements: String)