swift-playground

Import Kanna in playground

眉间皱痕 提交于 2019-12-06 04:28:36
Is there a way to add Kanna ( https://github.com/tid-kijyun/Kanna ) to Playground in XCode? I have tried to install it manually and via CocoaPods, but with no luck. I have also tried to pack it inside a Framework, but still no luck. Would appreciate any input. These are the error messages I am most often encountering: There is an interesting library in Github that allows run pods in Playground.It's still so young but it's very good. It's create a new project with the pod or pods installed and ready to test in the Playground. ThisCouldBeUsButYouPlaying I tested with your library and works fine:

Show TableView in Swift Playgrounds for iPad

跟風遠走 提交于 2019-12-06 02:42:25
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 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

Does iOS Playgrounds supports UIView animations?

ぐ巨炮叔叔 提交于 2019-12-05 12:45:35
问题 Is it possible to preview animation done for UIView with animateWithDuration in Playground? I am adding XCPShowView right after initialization of UIView and its shows everything it in a final state no matter what position on a timeline I will choose. 回答1: Xcode 7 update : XCPShowView is deprecated but you can see the animation in the playground liveView. And there is more coming soon: Interactive Playgrounds Here is an update to Joseph Chen sample code. I also changed the color to green as

Does Swift init(count:, repeatedValue:) work?

回眸只為那壹抹淺笑 提交于 2019-12-05 09:54:02
问题 Tested this from the reference: https://developer.apple.com/documentation/swift var string = String(count: 5, repeatedValue: "a") // string is "aaaaa" I got this error: Playground execution failed: error: :5:14: error: could not find an overload for 'init' that accepts the supplied arguments var string = String(count: 5, repeatedValue: "a") Does this actually work? 回答1: It seems that you have to explicitly pass in a Character type to it to function. This works for me. let char = Character("a"

NSUserDefaults in iOS Playground

半腔热情 提交于 2019-12-05 02:09:07
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.setObject("This is a test", forKey: "name") let readString = defaults.objectForKey("name") Any idea why

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

雨燕双飞 提交于 2019-12-05 01:24:30
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 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. Previously, all we could do with SKShapeNode, was initialize an instance, and then modify its path property.

UITableView get titleForHeadersInSection swift

霸气de小男生 提交于 2019-12-05 01:15:13
I want to set the title of the header in the section of UITableView. What is the syntax in swift to set the title of the header in the section. func tableView( tableView : UITableView, titleForHeaderInSection section: Int)->String { switch(section) { case 2: return "Title 2" break default: return "" break } } func tableView (tableView:UITableView , heightForHeaderInSection section:Int)->Float { var title = tableView.titleForHeaderInSection[section]; if (title == "") { return 0.0; } return 20.0; } func tableView (tableView:UITableView, viewForHeaderInSection section:Int)->UIView { var title =

What should I include in the .gitignore file for Swift playgrounds?

喜夏-厌秋 提交于 2019-12-05 00:33:03
I want to use Git for versioning my playgrounds, but I am not sure which files should be ignored and which ones I should commit. Currently I use following .gitignore file for playgrounds: # Xcode user data xcuserdata What else should be there? From the official github gitignore for Swift ## Playgrounds timeline.xctimeline playground.xcworkspace Suragch Whether it is a normal project or playgrounds, it is convenient and useful to use one of the standard .gitignore files for Swift. From the terminal cd into your project root folder (the one with the .xcodeproj file for a normal project) and run

How to get a Canvas in a Swift Playground

痴心易碎 提交于 2019-12-05 00:11:18
问题 I would like to get a canvas that I can use to draw on. The target would be an iOS based Swift playground. I searched the documentation and I could not found an object named Canvas, but if there is something similar to it then it would be good for me as well. 回答1: You can use something similar to this, note you don't have to use Sprite Kit classes. import UIKit import PlaygroundSupport import SpriteKit // Playground Container Setup // // let containerWidth: CGFloat = 667.0 let containerHeight

How does let x where x.hasSuffix(“pepper”) work

倾然丶 夕夏残阳落幕 提交于 2019-12-04 19:08:11
问题 In the code block below, I am having trouble understanding let x where x.hasSuffix("pepper") . let vegetable = "red pepper" switch vegetable { case "celery": let vegetableComment = "Add some raisins and make ants on a log." case "cucumber", "watercress": let vegetableComment = "That would make a good tea sandwhich" case let x where x.hasSuffix("pepper"): let vegetableComment = "Is it a spicy \(x)" default: let vegetableComment = "Everything tastes good in soup." } Console output