swift-playground

How do you create an iOS liveView in Xcode 8/Swift 3 [duplicate]

跟風遠走 提交于 2019-12-13 13:12:33
问题 This question already has answers here : iOS Playground doesn't show UI preview (8 answers) Closed 2 years ago . I can't figure out how to create and display a live view in an Xcode 8/Swift 3 Playground. If Apple has comprehensive documentation on playgrounds and live views, I can't find it, and all my searching online reveals either tutorials on Xcode 7 or the new iPad playgrounds. The few examples I have found set up Mac OS views, which is not what I want (I work mostly in iOS, so the code

Swift NStask function

你说的曾经没有我的故事 提交于 2019-12-13 11:20:48
问题 I'm a complete swift noob. Using this code in xcode I get the result I need. I created a command line binary "menubar" that takes several arguments. I normally run it in the terminal "/bin/menubar getip", "/bin/menubar/getuser". I want to create a function based on the following working code. import Cocoa import Foundation var task:NSTask = NSTask() var pipe:NSPipe = NSPipe() task.launchPath = "/bin/menubar" task.arguments = ["getip"] task.standardOutput = pipe task.launch() var handle = pipe

Delay in making http requests using Alamofire in playground

不问归期 提交于 2019-12-13 04:47:55
问题 I am running into a strange issue where Alamofire.request(.GET) statement in my playground gets executed after some delay in the playground Setup: I followed the following link to import Alamofire framework to test networking requests in xcode playground. This is the code I have in my playground. And when I look at the logs of my webserver the logs get updated after almost ~few minutes delay. I have verfied that it is not the log process that is causing delay. Making same http request using

Different results of rangeOfComposedCharacterSequenceAtIndex in playground and in app

a 夏天 提交于 2019-12-13 03:37:13
问题 rangeOfComposedCharacterSequenceAtIndex works differently in playground and in App, in playground mentioned below code returns as expected (location: 0, length: 4) let flagRange = "🇳🇴".rangeOfComposedCharacterSequenceAtIndex(0) But in application it returns (location: 0, length: 2) 来源: https://stackoverflow.com/questions/32831455/different-results-of-rangeofcomposedcharactersequenceatindex-in-playground-and-i

What is the largest possible size of a UIView in a Swift Playground?

女生的网名这么多〃 提交于 2019-12-13 03:36:36
问题 I'm trying to create a UIView in Swift Playground (in Xcode). My goal is to create the largest possible view. The current size is 1024 x 768. And if I try to increase the width or height, the view (when played in Live View) actually gets smaller which I think is happening so that it scales down to the window. But when I look at the Live View on 15-inch Macbook, there's a lot of space in the Live View -- the width can be increased, but I don't know how to increase it such that it actually

Fatal error: Only BidirectionalCollections can be advanced by a negative amount

故事扮演 提交于 2019-12-13 03:14:43
问题 How to convert an Array to a Set using Xcode Playground? We tried: let a = Array(0 ..< 1000) let s = Set(a) This produces at run time: Fatal error: Only BidirectionalCollections can be advanced by a negative amount Issue happening with both Xcode 9.4 Playground and Xcode 10 beta 3 Playground. 回答1: This is fixed in Xcode 10 beta 6 and newer, so I've updated the workaround to only apply for older swift versions. For older Xcode versions (like Xcode 9.4), this may be caused by the number of

Swift: Verifying is valid url in OS X playground

孤人 提交于 2019-12-13 01:25:03
问题 I'm trying to verify/validate url but when I do it always opens safari. Any of you know how can accomplish this without open safari. Here is my code: func validateUrl (urlString: String?) -> Bool { let url:NSURL = NSURL(string: urlString!)! if NSWorkspace.sharedWorkspace().openURL(url) { return true } return false } print (validateUrl("http://google.com")) I'll really appreciate your help. 回答1: There's two things to check: if the URL itself is valid, and if the server responds without error.

How do I get the .mlmodel to be used in Swift Playground?

风格不统一 提交于 2019-12-13 00:38:20
问题 I have already converted the .mlmodel to .mlmodelc , and I have put it in the resources folder. Im using Vision framework and MNIST model, following this tutorial (https://www.youtube.com/watch?v=bOg8AZSFvOc), but using swift playground. What am i missing? (im using .playground files, not .playgroundbook files) line of code: guard let visionModel = try? VNCoreMLModel(for: MNIST().modelc) else {fatalError("can not load Vision ML model")} Error message: use of undefined identifier 'MNIST'

How to load an image into an Xcode 9 playground?

只愿长相守 提交于 2019-12-12 19:30:48
问题 I've spent hours trying to simply gain access to image data in my Swift Playground. I've followed many tutorials that recommend adding a resource folder as a sibling dir in the dir. your playground is in. Or to drag images into the Resources folder in the playground Navigator. Nothing has worked. What do I have to do to load an image view in playground? 回答1: I solved this problem on my side when I import PlaygroundSupport mark Resources Folder and tap + icon Choose Add files to 'Resources'

swift playground UITextField spawns keyboard that is too big

帅比萌擦擦* 提交于 2019-12-12 07:52:54
问题 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