swift-playground

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

安稳与你 提交于 2019-12-03 22:25:39
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? It seems that you have to explicitly pass in a Character type to it to function. This works for me. let char = Character("a") let string = String(count: 5, repeatedValue: char) Although, there may be bug mixed in with all this as

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

落爺英雄遲暮 提交于 2019-12-03 22:18:48
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 bit more insight, but still not clear how to fix: 24/10/2015 10:16:10,193 lsd[279]: LaunchServices:

Xcode autocomplete does not work in Sources folder of Swift playgrounds

泄露秘密 提交于 2019-12-03 16:40:39
问题 I am working on a Swift playground that contains multiple files in the Sources folder alongside the main file. When I type something, for instance, "UI", in the main file, I get the expected autocomplete suggestions. However, when I do the same in files in the Sources folder, I get a "dumb" autocomplete menu as seen in this question: Xcode 9 Autocomplete Not Working 100% - Partially Working I have tried deleting DerivedData as suggested in the above question, and have even gone to the lengths

swift playground UITextField spawns keyboard that is too big

有些话、适合烂在心里 提交于 2019-12-03 13:16:05
Swift in playground on Mac OS. When the user clicks in a UItextfield, a keyboard spawns but it is very large compared to the view and only the first few keys are available. minimal example: import UIKit import PlaygroundSupport class TesterViewController : UIViewController { var testTextField : UITextField! override func loadView() { let view = UIView() view.backgroundColor = .white testTextField = UITextField() testTextField.borderStyle = .roundedRect testTextField.text = "" view.addSubview(testTextField) testTextField.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint

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

最后都变了- 提交于 2019-12-03 12:38:01
This question already has an answer here: How to import own classes from your own project into a Playground 6 answers 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 playgrounds do not appear to share the concept of target membership like .swift/.m Anyone had any success with this or perhaps a

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

懵懂的女人 提交于 2019-12-03 12:23:37
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 vegetableComment: Is it a spicy red pepper It seems like the following logic is happening. x = vegetable if (x's

Xcode 6 Beta / Swift - Playground not updating

折月煮酒 提交于 2019-12-03 11:34:58
I was playing around with the Playground feature of Xcode 6's first beta - and I notice half the time the Playground doesn't update (simply doesn't display the result calculation or how many loop iterations are happening) simple code/loops/functions that are in there. Even the Swift Tour https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html has several lines of code that don't show up in Playground. If you mess with the code sometimes it will show up, by moving the code around or placing it elsewhere. Anyone else? Any fixes? Is

Get playground to display all loop results

自闭症网瘾萝莉.ら 提交于 2019-12-03 08:46:02
问题 I'm using an xcode 7 playground, and I want to know how to make the playground display all the results printed out by a loop. for example: This will tell me the loop ran 4 times, but it will only display the last value of the iteration. Is there a way I can make it show all values? 回答1: Right click on the inline quick look (the gray rounded rectangle with "4" in it). There's an option to show all the results in a list: You can also show everything that's been printed to the console for the

Xcode autocomplete does not work in Sources folder of Swift playgrounds

…衆ロ難τιáo~ 提交于 2019-12-03 06:42:02
I am working on a Swift playground that contains multiple files in the Sources folder alongside the main file. When I type something, for instance, "UI", in the main file, I get the expected autocomplete suggestions. However, when I do the same in files in the Sources folder, I get a "dumb" autocomplete menu as seen in this question: Xcode 9 Autocomplete Not Working 100% - Partially Working I have tried deleting DerivedData as suggested in the above question, and have even gone to the lengths of reinstalling Xcode entirely. However, the problem has not gone away. I have created a new

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

拈花ヽ惹草 提交于 2019-12-03 06:02:12
Basically I would like to test a chart drawing in a Swift playground in NSView. 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)) view.color = NSColor.greenColor() XCPShowView("chart", view) for var i = 0; i < 100; ++i { view.y = CGFloat