swift-playground

Is .playground a swift file? Who can 'see' it?

送分小仙女□ 提交于 2020-02-21 11:18:53
问题 I'm trying to figure out what .playground file really is. If it's a source file, it cannot (as far as I've tried) be seen by other swift files in the project, nor other .playground files or vice versa. Is a project supposed to have one such file? Are they a kind of swift file? I know what it (.playground file) does, I just can't figure out how it fits in the project. 回答1: A .playground file is actually a bundle directory, which can be verified by right clicking it and selecting "Show Package

Is .playground a swift file? Who can 'see' it?

妖精的绣舞 提交于 2020-02-21 11:18:28
问题 I'm trying to figure out what .playground file really is. If it's a source file, it cannot (as far as I've tried) be seen by other swift files in the project, nor other .playground files or vice versa. Is a project supposed to have one such file? Are they a kind of swift file? I know what it (.playground file) does, I just can't figure out how it fits in the project. 回答1: A .playground file is actually a bundle directory, which can be verified by right clicking it and selecting "Show Package

Bug in Swift array subscript indexing?

喜欢而已 提交于 2020-01-25 04:28:05
问题 I've isolated some Swift code from my project that can be pasted into a Playground. It produces an error "Could not find an overload for '+' that accepts the supplied arguments" both in normal Xcode editing and the Playground. The error refers to the last (non-trivial) line. import UIKit let points = 40 let max = points-1 let L = 10.0 let Deltat = 0.01 let Deltax = L/Double(points) var a = [Double](count: points, repeatedValue: 0.0) var b = [Double](count: points, repeatedValue: 0.0) var c =

Xcode 11 iOS playgrounds no longer symlink playgroundSharedDataDirectory - bug or feature?

时光毁灭记忆、已成空白 提交于 2020-01-23 01:15:26
问题 Xcode 11 Playgrounds seemingly changed the behavior of playgroundSharedDataDirectory : To reproduce, paste the below in a playground and execute it in Xcode 10 and Xcode 11 respectively: import PlaygroundSupport print(playgroundSharedDataDirectory) let str = try String(contentsOf: playgroundSharedDataDirectory.appendingPathComponent("data.json")) // assuming you create ~/Documents/Shared Playground Data/data.json playgroundSharedDataDirectory resolves to: Xcode 11.2: iOS: file:///Users/

How do you prevent Xcode 7 Playgrounds from automatically running?

那年仲夏 提交于 2020-01-22 06:57:04
问题 I'm working on an Xcode 7 Playground that has many things running at once. Whenever I make an edit, it refreshes, restarts what was running and runs through the entire code again. That crashes my playground around every 15 minutes. Is there a way to prevent playgrounds from automatically running whenever I make an edit? 回答1: In the lower-left part of the Playground there's a right-facing blue arrow, looking like a "play" button. Do a long click on this button and you will get two options:

Swift random number [duplicate]

那年仲夏 提交于 2020-01-13 09:02:51
问题 This question already has answers here : Crash when casting the result of arc4random() to Int (7 answers) Closed 5 years ago . I'm having problems with this drawRandomCard function. It works just like it should for some time, but eventually it crashes the application. Here is the code: import Foundation var cardDeck = Array<PlayingCard>() class Deck { func addCard(card : PlayingCard , atTop : Bool = false){ if atTop { cardDeck.insert(card, atIndex: 0); }else{ cardDeck += card } } func

How to convert 4 bytes to a Swift float?

这一生的挚爱 提交于 2020-01-13 08:16:58
问题 I'm writing a MsgPack parser in Swift as a way to learn the language. It doesn't feel very well suited to the task but I've been making progress. Now I've hit a block where I can't seem to convince it to convert 4 bytes into a float. var bytes:Array<UInt8> = [0x9A, 0x99, 0x99, 0x41] //19.20000 var f:Float = 0 memccpy(&f, &bytes, 4, 4) print(f) In the playground I get: fatal error: Can't unwrap Optional.None Playground execution failed: error: Execution was interrupted, reason: EXC_BAD

How to use Swift playground to display NSView with some drawing?

青春壹個敷衍的年華 提交于 2020-01-12 04:44:09
问题 Basically I would like to test a chart drawing in a Swift playground in NSView. 回答1: Here is what I am using now: class CustomView: NSView { init(frame: NSRect) { super.init(frame: frame) } override func drawRect(dirtyRect: NSRect) { color.setFill() NSRectFill(self.bounds) NSColor.yellowColor().setFill() var r = NSMakeRect(0, y, self.bounds.width, 5) NSRectFill(r) } var color = NSColor.greenColor() var y: CGFloat = 0 } var view = CustomView(frame: NSRect(x: 0, y: 0, width: 300, height: 300))

Swift Playground - “Use of unresolved identifier 'myClass'” but still compiles

会有一股神秘感。 提交于 2020-01-11 13:12:32
问题 I am currently experimenting in Swift Playgrounds, and am trying out SpriteKit. My playground is working as expected, and runs, but Xcode has an error saying "Use of unresolved identifier 'myClass'". The playground still runs perfectly still though. Here is my code: import UIKit import PlaygroundSupport import SpriteKit let frame = CGRect(x: 0, y: 0, width: 800, height: 600) let mySKScene = myClass() let view = SKView(frame: frame) view.presentScene(mySKScene) PlaygroundPage.current.liveView

Swift Playground - “Use of unresolved identifier 'myClass'” but still compiles

五迷三道 提交于 2020-01-11 13:11:04
问题 I am currently experimenting in Swift Playgrounds, and am trying out SpriteKit. My playground is working as expected, and runs, but Xcode has an error saying "Use of unresolved identifier 'myClass'". The playground still runs perfectly still though. Here is my code: import UIKit import PlaygroundSupport import SpriteKit let frame = CGRect(x: 0, y: 0, width: 800, height: 600) let mySKScene = myClass() let view = SKView(frame: frame) view.presentScene(mySKScene) PlaygroundPage.current.liveView