相关疑难解决方法(0)

如何使用swift playground打印到控制台?

我一直在关注苹果指南的新语言swift,但我不明白为什么右边的栏只显示"Hello,playground"而不是"Hello,world".有人可以解释为什么println没有在右边打印?

// Playground - noun: a place where people can play

import Cocoa

var str = "Hello, playground"

println("Hello, world");
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

swift xcode6 swift-playground

97
推荐指数
4
解决办法
11万
查看次数

在swift,iOS游乐场中读取文件

在搜索了许多(很多!)快速游乐场问题甚至制作这些代码后,我仍然在苦苦挣扎.

我已经将一个文本文件放在Resources包内容的文件夹中,它在playground(/var/folders/ ...)生成的运行临时文件中显示为别名(链接).

import UIKit

let bundle = NSBundle.mainBundle()

let myFilePath = bundle.pathForResource("dict1", ofType: "txt")

println(myFilePath)    // <-- this is correct, there is a shortcut to the Resource file at this location

var error:NSError?

var content = String(contentsOfFile:myFilePath!, encoding:NSUTF8StringEncoding, error: &error)

println(content!)  // <-- this is *NOT* the file contents [EDIT: see later note]

// Demonstrate there's no error
if let theError = error {
    print("\(theError.localizedDescription)")
} else {
    print("No error")
}
Run Code Online (Sandbox Code Playgroud)

问题是,content …

xcode ios swift swift-playground

12
推荐指数
2
解决办法
2万
查看次数

标签 统计

swift ×2

swift-playground ×2

ios ×1

xcode ×1

xcode6 ×1