swift-playground

Error running playground. Unable to find suitable target device. (iOS Swift)

北慕城南 提交于 2019-11-30 06:50:35
I created a new project in XCode. File > New > Playground (option+shift+cmd+N) I restarted my XCode and also rebooted my system, but still same error. Try navigating to the Xcode Menu Window >> devices (shift+cmd+2) a new window will pop up. On the bottom left, add a new simulator, specifically one running on iOS 8.0 to the existing list. Restart Xcode. From the developer forums, this worked for me: Quit Xcode Delete the folder /Users/<username>/Library/Developer/CoreSimulator/Devices . For example, in Terminal: rm -rf ~/Library/Developer/CoreSimulator/Devices In Terminal: killall -9 com.apple

Declarations in extensions cannot override yet error in Swift 4

夙愿已清 提交于 2019-11-30 05:33:43
I have an extension: public extension UIWindow { override public func topMostController()->UIViewController? { ... } } but for my topMostController I get the next error: Declarations in extensions cannot override yet error It works well for Swift 3.1, but for Swift 4 I get this error. How can it be fixed? What did they change in Swift 4? It will work if you make the base implementation @objc . See Hamish's answer for a detailed explanation about the internals. Overriding methods declared in extensions is a bit tricky to do correctly. Objective-C supports it, but it's not absolutely safe. Swift

Swift 2.0 code works in Xcode but not in Playground

我怕爱的太早我们不能终老 提交于 2019-11-30 04:57:49
问题 I'm learning Swift and have been frustrated trying to figure out how I'm unable to load files. It turns out that the code works in Xcode but does not work in a playground. What is the reason for this? Here's the code: func testFileLoad(){ let myFilePath: String = "/Users/clay/Desktop/test.txt" let t: Bool = NSFileManager.defaultManager().fileExistsAtPath(myFilePath) print(t) let s: String = try! String(contentsOfFile: myFilePath, encoding: NSUTF8StringEncoding) print(s) do { let p: String =

How to Read and Write data to a text file in Swift using playground? [duplicate]

时间秒杀一切 提交于 2019-11-30 04:37:30
问题 This question already has answers here : Swift Playground - Files are not readable (3 answers) Closed 4 years ago . I read through these SO links for the answer 1. Read a file/URL line-by-line in Swift 2. Read and write data from text file Link 2 Provided me the solution but the problem is directory . It is by default Document directory of the current project. So if i want to read a file from "/Users/Prem/Desktop/File.txt" , what modification i should make to that code? How to work with

How to reopen Console Output in a Swift Playground?

折月煮酒 提交于 2019-11-30 01:08:46
问题 I was happily println ing to the Console Output in the Assistant Editor of a Swift/Xcode 6 Playground (see this SO thread for more info), until I decided to try clicking the [X] to close the Console Output. How do I bring the Console Output back?? 回答1: This eluded me for a while, too. You want View menu -> Assistant Editor -> Show Assistant Editor . Once you see the pane that holds the console output, if you still aren't seeing the right thing, make any change that will cause a println() to

No such module 'Cocoa' in Swift Playground

时光总嘲笑我的痴心妄想 提交于 2019-11-29 22:56:01
I'm trying to follow some of the code used in the WWDC playgrounds session, I'm trying to import the Cocoa framework with: import Cocoa But I get the following error in the assistant editor Playground execution failed: error: <REPL>:3:8: error: no such module 'Cocoa' I'm at 41:20 in the video if that helps at all. Matt Gibson You are using an iOS playground (UIKit-based), not an OS X playground (Cocoa-based). Try creating a new playground and choosing "OS X" as the type instead of "iOS". It should work fine after that. You can also change the type for an existing playground in the File

Using NSTimer in swift playground [duplicate]

谁都会走 提交于 2019-11-29 22:07:45
问题 This question already has answers here : How do I run Asynchronous callbacks in Playground (8 answers) Closed 4 years ago . I'd like to know how to use an NSTimer inside a Swift Playground. This question has been asked before, but none of the answers actually answered the question. Here's my Playground code: import Foundation class MyClass { func startTimer() { NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "onTimer:", userInfo: nil, repeats: true) } func onTimer(timer

Swift Playgrounds: Replacement for captureValue(_:withIdentifier:)

╄→尐↘猪︶ㄣ 提交于 2019-11-29 18:04:22
问题 Xcode 7.3 has deprecated XCPlaygroundPage.currentPage.captureValue(_:withIdentifier:) . Its predecessor, XCPCaptureValue() , was deprecated in Xcode 7.1. I'm wondering if there is any replacement, apart from implicit capture of collections and in loops? Apart from being more flexible using the explicit approach, the ability to add captions to graphs seems to be gone with the deprecation/removal (although the symbols are found, the aforementioned deprecated methods don't do anything, or at

Read file in swift, iOS playground

走远了吗. 提交于 2019-11-29 17:43:02
问题 Having searched through the many (many!) swift playground questions to even craft this code, I'm still struggling. I've placed a text file in the Resources folder of package contents, and it appears as an alias (link) in the running temp files generated by the playground ( /var/folders/ ... ). import UIKit let bundle = NSBundle.mainBundle() let myFilePath = bundle.pathForResource("dict1", ofType: "txt") println(myFilePath) // <-- this is correct, there is a shortcut to the Resource file at

How To Get CoreML In Pure Playground Files

前提是你 提交于 2019-11-29 16:22:18
I am using a .playground file and I can't seem to add my CoreML model to it. I drag it into the Resources folder and this is my code: func predict(image: CGImage) { let model = try! VNCoreMLModel(for: Inceptionv3().model) let request = VNCoreMLRequest(model: model, completionHandler: results) let handler = VNSequenceRequestHandler() try! handler.perform([request], on: image) } However, I get the error saying: Use of Undeclared Type Inceptionv3 Can someone please help me out? The compiler raises this error, because it cannot find a declaration of the class Inceptionv3, that you try to