swift-playground

Swift Playgrounds and Playground Books

不打扰是莪最后的温柔 提交于 2019-12-24 08:47:18
问题 I recently tried opening/editing a .playgroundbook project in Xcode Version 8.3.2 (8E2002), and was somewhat surprised that it didn't open as a "liveView Playground" ( I realize it's mostly a package of .swift files with manifests ). Maybe I'm totally missing the point here, or was the format never intended to be used this way? 回答1: Playground Book Package: Creating Playground Books indicates that… You need to use both a Mac running Xcode and an iPad to create a playground book. The only

Xcode freezes when trying to execute this in a Swift playground?

寵の児 提交于 2019-12-24 05:32:09
问题 I was simply experimenting with Swift, so I threw together this in my playground: // Playground - noun: a place where people can play import Cocoa func printCarInfo(car:Car?) -> Void { if let _car = car { println("This is a " + _car.make + " " + _car.model + " from \(_car.year). It's worth $" + _car.price + ".") } } class Car { init(make:String, model:String, year:UInt, color:NSColor, price:UInt) { self.make = make self.model = model self.year = year self.color = color self.price = price }

Xcode freezes when trying to execute this in a Swift playground?

坚强是说给别人听的谎言 提交于 2019-12-24 05:32:03
问题 I was simply experimenting with Swift, so I threw together this in my playground: // Playground - noun: a place where people can play import Cocoa func printCarInfo(car:Car?) -> Void { if let _car = car { println("This is a " + _car.make + " " + _car.model + " from \(_car.year). It's worth $" + _car.price + ".") } } class Car { init(make:String, model:String, year:UInt, color:NSColor, price:UInt) { self.make = make self.model = model self.year = year self.color = color self.price = price }

playground program doesn't run

喜欢而已 提交于 2019-12-24 01:43:33
问题 I'm relatively new in app development but for interest I want to implement this application on a playground project on Xcode: http://merowing.info/2015/11/the-beauty-of-imperfection/ All the errors are corrected, but when I press the run Playground button it says "Running" forever without displaying anything. Do you know what I'm doing wrong? import UIKit import XCPlayground import QuartzCore import PlaygroundSupport class Animator { class TargetProxy { init (target: Animator) { self.target =

Swift Playground XCPShowView “Unable to satisfy constraints”

给你一囗甜甜゛ 提交于 2019-12-23 16:34:37
问题 I'm trying to get a Live View to show a simple animation in a Swift Playground. Whenever I import the XCPlayground framework to execute the XCPShowView function i get this error: Playground execution failed: error: Couldn't lookup symbols:_CGPointMake The error changes for a few other "symbols" as well, including CGRectMake . After being advised to modifying my code to remove the "make" from methods such as CGRectMake I still get an error from Xcode when I try to animate my view. The error

Swift three double quotes

北战南征 提交于 2019-12-23 06:58:08
问题 I am new to Swift. The docuentation says: Use three double quotes (""") for strings that take up multiple lines. Indentation at the start of each quoted line is removed, as long as it matches the indentation of the closing quote. For example: let quotation = """ Even though there's whitespace to the left, the actual lines aren't indented. Except for this line. Double quotes (") can appear without being escaped. I still have \(apples + oranges) pieces of fruit. """ However, I copied this

Syntax to create Dictionary in Swift

限于喜欢 提交于 2019-12-23 02:38:36
问题 As far as I know there are two ways to create an empty dictionary in swift var randomDict = [Int:Int]() or var randomDict = Dictionary<Int, Int>() Is there any difference between these? Both versions seems to work just the same. 回答1: No, both are same. From Apple's Book on Swift: The type of a Swift dictionary is written in full as Dictionary<Key, Value> You can also write the type of a dictionary in shorthand form as [Key: Value] . Although the two forms are functionally identical, the

Terminology concerning UnsafeMutablePointer's destroy()

ⅰ亾dé卋堺 提交于 2019-12-22 17:58:10
问题 /// Destroy the object the pointer points to. /// /// Precondition: the memory is initialized. /// /// Postcondition: the value has been destroyed and the memory must /// be initialized before being used again. func destroy() What do the terms object , memory and value mean in this context? 回答1: When doing low-level programming where you manage the memory yourself instead of having a language runtime handle it for you, using memory is a two-stage process. First, you allocate a region of

Mouse events (NSTrackingArea) in Playground not working

北战南征 提交于 2019-12-22 17:28:13
问题 I have a a subclass of NSView which contains the following NSTrackingArea code. But for some reason the mouse events won't trigger in Playground. The viewWillMoveToWindow is being called, but nothing else seems to fire. Does anyone have a clue to what is missing? class MyView: NSView { private var trackingArea: NSTrackingArea = NSTrackingArea() // Other stuff omitted here... // ... override func viewWillMoveToWindow(newWindow: NSWindow?) { // Setup a new tracking area when the view is added

Undeclared Type 'NSView' in Playground

99封情书 提交于 2019-12-22 12:27:41
问题 For an OSX Playground I enter the following code: import Cocoa class PlayView : NSView { override func drawRect(dirtyRect: NSRect) { let blue = NSColor.blueColor() blue.setFill() NSRectFill(self.bounds) } } var view = PlayView(frame: NSRect(x: 0, y: 0, width: 200, height: 200)) I then get this output: Playground execution failed: <EXPR>:12:18: error: use of undeclared type 'NSView' class PlayView : NSView { ^~~~~~ <EXPR>:14:39: error: use of undeclared type 'NSRect' override func drawRect