我的Swift Playground与Xcode项目相关联,用于错误突出显示和填充。在尝试新的运行时,发生了这种情况 -
Playground execution failed:
error: Foo.playground:36:21: error: use of unresolved identifier 'GameScene'
let scene = GameScene()
^~~~~~~~~
它已在Sources中正确定义,而且之前从未发生过这种情况,因此我认为它是Sources文件夹的一个问题。并且在第二次运行时 - 它就是。
Playground execution failed:
error: /var/folders/ff/mh9n4vn14w58hmrbq4235wzm0000gn/T/playground3-a91091..swift:3:8: error: no such module 'Foo_Sources'
import Foo_Sources
^
该位置包含...
@_silgen_name ("playground_logger_initialize") func $builtin_logger_initialize ()
@_silgen_name ("playground_log_hidden") func $builtin_log_with_id<T> (_ object : T, _ name : String, _ id : Int, _ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject
@_silgen_name ("playground_log_scope_entry") func $builtin_log_scope_entry (_ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject
@_silgen_name ("playground_log_scope_exit") func $builtin_log_scope_exit (_ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject
@_silgen_name ("playground_log_postprint") func $builtin_postPrint (_ sl : Int, _ el : Int, _ sc : Int, _ ec: Int) -> AnyObject
@_silgen_name ("DVTSendPlaygroundLogData") func $builtin_send_data (_ : AnyObject!)
$builtin_logger_initialize()
import Foo_Sources
#sourceLocation(file: "Foo.playground", line: 1)
老实说,我很难过。在没有xcode项目的情况下单独运行会使编译停顿,清理或按下Clean Build Folder也无法提供帮助。
Stack Overflow,the WWDC Scholars forum和the Swift Reddit正在询问此问题。
编辑:有些代码被剥离了......(不是真正的代码,但足以让人知道它的外观)
主要游乐场文件:(Contents.swift)
import UIKit
导入PlaygroundSupport 导入SpriteKit
class FooViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let sceneView = SKView(frame: CGRect(x: 0 , y:0, width: 375, height: 667))
let scene = GameScene()
scene.scaleMode = .resizeFill
sceneView.presentScene(scene)
self.view.addSubview(sceneView)
}
}
PlaygroundSupport.PlaygroundPage.current.liveView = FooViewController()
主要游戏场景:(被召唤的人,让我相信来源不是被建造的)
public class GameScene: SKScene {
public override func didMove(to view: SKView) {
backgroundColor = .white
}
}
我尝试过的事情:
/var/folders/ff/mh9n4vn14w58hmrbq4235wzm0000gn/T
并删除任何以playground
Clean
Clean Build Folder
Library/Developer/Xcode/DerivedData