swift-playground

Show TableView in Swift Playgrounds for iPad

坚强是说给别人听的谎言 提交于 2019-12-22 10:45:49
问题 Everything works fine except the last line where I try to show the tableView in live view does not work: PlaygroundPage.current.liveView = controller I can't figure out what I'm getting wrong? import UIKit import PlaygroundSupport import Foundation class TableViewController: UITableViewController { let tableData = ["Matthew", "Mark", "Luke", "John"] override func viewDidLoad() { super.viewDidLoad() print("Hello Matt") } override func numberOfSections(in tableView: UITableView) -> Int { return

NSUserDefaults in iOS Playground

房东的猫 提交于 2019-12-22 04:27:10
问题 There seems to be a strange issue with iOS Playgrounds where NSUserDefaults always returns nil instead of the actual value. In an iOS Playground the last line wrongly returns nil . import UIKit let defaults = NSUserDefaults.standardUserDefaults() defaults.setObject("This is a test", forKey: "name") let readString = defaults.objectForKey("name") In an OSX Playground the last line correctly returns "This is a test". import Cocoa let defaults = NSUserDefaults.standardUserDefaults() defaults

SKShapeNode(circleOfRadius) results in “unrecognized selector sent to class” in Playground for OSX

狂风中的少年 提交于 2019-12-22 03:42:42
问题 The following playground results in a timeline error "unrecognized selector sent to class..." import SpriteKit let node = SKShapeNode(circleOfRadius: 10) Screenshot Seems to work ok when platform is iOS. Running 10.9.3 回答1: It's because you're running it on an OS X version that's older than the API you're trying to use. The code you're using requires OS X 10.10, or iOS 8 and up. The OS X 10.10 API Differences confirm that all of SKShapeNodes custom initializers have just been added in 10.10.

Rename default rendered headings like “Example” in Swift Markup language

旧街凉风 提交于 2019-12-21 10:47:59
问题 Raw Markup Rendered Markup How do I change the word Example in the "Rendered Markup" to anything I would like? 回答1: Custom callouts You can make use of a Custom Callout /*: # Hello, playground! The print() function in Swift * callout(Custom Title): print("Hello, playground!") */ Rendered as (using Dusk theme) Additional pre-defined callouts If you don't fancy the color of the Custom Callout, there are a few other callouts (in addition to Example) available for use in a playground /*: # Hello,

iOS/tvOS playground fails with “Unable to find execution service for selected run destination”

痴心易碎 提交于 2019-12-21 06:51:33
问题 After migrating to XCode 7.1 I can not use playground with iOS and tvOS platforms. Only OS X works. Simplest playground code produces error message: Unable to find execution service for selected run destination I suspect it has to do with XCode not finding the right simulator, however I have no idea where and how to configure it. I tried playground in the existing project, as well as just newly created one from the splash screen. Any ideas what might be wrong? UPDATE: Checking console gives a

Is it possible to import third-party Objective-C code into a Swift playground? [duplicate]

試著忘記壹切 提交于 2019-12-21 03:51:42
问题 This question already has answers here : How to import own classes from your own project into a Playground (6 answers) Closed 5 years ago . As suggested here I've been able to import my existing Objective-C code into a .swift file via the bridging header. As of yet I've been unable to do something similar with a swift playground - it does not seem to recognise the header in the same way that a swift file does. Interestingly, and possibly suggestive of a negative to my question is that

How to use frameworks imported with carthage in swift playground

大兔子大兔子 提交于 2019-12-20 12:03:29
问题 i have a swift project with some frameworks added via carthage. Is it possible to use those frameworks in playground inside project and how to use it, because import Argo doesn't work :( 回答1: This stopped working at some point. Sigh What I do now is Create a macOS > Command Line Tool. Create a Cartfile with github "ReactiveX/RxSwift" and run carthage update --platform iOS Go to the command line tool target and add the frameworks from Carthage/Build/iOS in Linked frameworks and Libraries Add

How can I print to console in Swift Playgrounds on iPad?

亡梦爱人 提交于 2019-12-20 06:19:23
问题 I would like to debug a method deep inside my "Sources" folder within a Swift Playground. public func wannaDebugThis() { let x = 42 let text = "Debug message with useful information: x = \(x)" print(text) } Within a macOS playground, the print output is shown in the debug area, as described in this question. On iPad however, the print statement seems to be ignored. Even within Console.app on mac, I cannot find the desired output. How do I write debug statements on iPad and where do I find

Why is UInt64 max equal -1 in Swift?

百般思念 提交于 2019-12-19 20:49:14
问题 Using Swift, wether in terminal or playground, when I enter the following on a new line: UInt64.max I get a result value of -1. Is this a bug? Edit: Examples $ xcrun swift Welcome to Swift! Type :help for assistance. 1> UInt64.max / 2 $R1: UInt64 = 9223372036854775807 2> UInt64.max / 2 + 1 $R2: UInt64 = -9223372036854775808 3> UInt64.max $R3: UInt64 = -1 4> println(UInt64.max / 2) 9223372036854775807 5> println(UInt64.max / 2 + 1) 9223372036854775808 6> println(UInt64.max)

Why is UInt64 max equal -1 in Swift?

大兔子大兔子 提交于 2019-12-19 20:49:11
问题 Using Swift, wether in terminal or playground, when I enter the following on a new line: UInt64.max I get a result value of -1. Is this a bug? Edit: Examples $ xcrun swift Welcome to Swift! Type :help for assistance. 1> UInt64.max / 2 $R1: UInt64 = 9223372036854775807 2> UInt64.max / 2 + 1 $R2: UInt64 = -9223372036854775808 3> UInt64.max $R3: UInt64 = -1 4> println(UInt64.max / 2) 9223372036854775807 5> println(UInt64.max / 2 + 1) 9223372036854775808 6> println(UInt64.max)