小编Eth*_*ort的帖子

componentsSeparatedByString()Swift 3中的错误

var numbers = "Hello,Goodbye,Hi,Bye"
var numbersArr = numbers.componentsSeparatedByString(",")
Run Code Online (Sandbox Code Playgroud)

//["Hello"."Goodbye","Hi","Bye"]

以上是我正在尝试做的基本表示.我正在尝试使用componentsSeparatedByString()逗号将字符串拆分为数组,其中数组的每个组件都位于原始字符串的每个逗号之间.

我正在使用IBM Swift Sandbox(抱歉,我在Windows上:)),在Swift 3.0中,我收到此错误消息:

value of type 'String' has no member 'componentsSeparatedByString'
Run Code Online (Sandbox Code Playgroud)

我知道Swift 3相当新,这就是为什么我找不到这个错误的任何其他参考.

swift3

32
推荐指数
1
解决办法
3万
查看次数

UIDocumentInteractionController 文件附件错误

所以我正在从 Xcode 导出一个 .txt 文件,但是每当我尝试导出它时,比如通过电子邮件,它会创建一封没有附件和空消息的电子邮件。当我尝试将其导出到 iCloud Drive 时,白屏出现一秒钟,然后离开。当我检查 iCloud Drive 时,该文件不存在。这里有什么问题?

let message = testLabel.text

func getDocumentsDirectory() -> NSString {
    let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
    let documentsDirectory = paths[0]
    return documentsDirectory as NSString
}

let filePath = getDocumentsDirectory().appendingPathComponent("matrixFile.txt")

do{
    try message?.write(toFile: filePath, atomically: true, encoding: String.Encoding.utf8)
}catch let error as NSError{
    testLabel.text = String(describing: error)
}

let documentInteractionController = UIDocumentInteractionController()
documentInteractionController.url = NSURL.fileURL(withPath: filePath)
documentInteractionController.uti = "public.data, public.content"
documentInteractionController.name = "matrixFile"
documentInteractionController.presentOptionsMenu(from: view.frame, in: view, animated: true)
Run Code Online (Sandbox Code Playgroud)

uidocumentinteraction swift swift3

3
推荐指数
1
解决办法
1592
查看次数

如何在iOS应用程序中导入和读取文件?

这是我的文本文件导出和导入难题的第二部分。现在,我有写代码和导出代码。难题的最后一部分是导入代码和读取代码。我想从电子邮件中提取附件并将​​其导入到应用程序中,以便我可以阅读。我有基本的阅读代码:

@IBAction func readButton(_ sender: UIButton) {
    let filePath = getDocumentsDirectory().appendingPathComponent("matrixFile.txt")
    do {
        try displayField.text = String(contentsOfFile: path!,
                                       encoding: String.Encoding.utf8)
    } catch let error as NSError{
        displayField.text = String(describing: error)
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我也想知道导入时是什么filePath。我调整了info.plist的导出功能,但是否需要对此做更多更改?这是我当前添加的内容: 在此处输入图片说明 提前致谢。

import ios swift

3
推荐指数
1
解决办法
3533
查看次数

UInt32数组为Double数组Swift

我需要在swift中乘以2个矩阵,所以为了使用加速,我需要2个类型为double的数组.问题是,我需要乘法的两个数组是类型UInt32.无论如何将UInt32数组转换为双数组?

var UInt32TestArray: [UInt32] = [1,4,2,3]
var Int32TestArray: [Double] = [Double](UInt32) //Doesn't work
Run Code Online (Sandbox Code Playgroud)

arrays uint32 swift

2
推荐指数
1
解决办法
1531
查看次数

标签 统计

swift ×3

swift3 ×2

arrays ×1

import ×1

ios ×1

uidocumentinteraction ×1

uint32 ×1