swift-playground

Animations not working in ios playground

孤者浪人 提交于 2019-12-01 05:19:56
问题 This is my animation method (PreloaderView.swift) public func performAction(action: PreloaderAction) { let highOpacity = CABasicAnimation.init(keyPath: "opacity") let middleOpacity = CABasicAnimation.init(keyPath: "opacity") let lowOpacity = CABasicAnimation.init(keyPath: "opacity") if action == .PreloaderActionNone { self.thirdShape.removeAllAnimations() self.firstShape.opacity = 0.3; self.secondShape.opacity = 0.5 self.thirdShape.opacity = 1.0 } else if action == .PreloaderActionFailure {

CABasicAnimation in Swift Playground

妖精的绣舞 提交于 2019-12-01 04:13:25
Been going nuts trying to get a live view of an animation in a Swift Playground like in the WWDC "Swift Playgrounds" video. I tried to do a UIView.animateWithDuration with no luck so I am now trying to do a CABasicaAnimation because this seems to be what was used in the demo. I'be gotten rid of a lot of confusing errors and have imported the proper frameworks but am still having no luck getting my little circle to do anything but sit still in the center of my XCPShowView . Here is my code: import Foundation import XCPlayground import UIKit import QuartzCore //Circle Button class

Swift 2.0 code works in Xcode but not in Playground

六眼飞鱼酱① 提交于 2019-11-30 20:29: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 = try String(contentsOfFile: myFilePath, encoding: NSUTF8StringEncoding) print(p) } catch { print("nope")

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

為{幸葍}努か 提交于 2019-11-30 20:08:21
This question already has an answer here: Swift Playground - Files are not readable 3 answers 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 custom directory to read and write data in a text file? let dirs : [String]? = NSSearchPathForDirectoriesInDomains

How can I display views using autolayout constraints in Xcode playground?

痴心易碎 提交于 2019-11-30 13:01:26
I am trying to display views configured with autolayout constraints in XCode playground , but it doesn't seem to work. It's like playground ignores the constraints completely, and I can't find information about this issue anywhere. Here's the code I tried: let view = UIView() view.frame = CGRectMake(0, 0, 400, 200) view.backgroundColor = UIColor.lightGrayColor() let label = UILabel() // I can only see the label if I set a frame // UILabel(frame: CGRectMake(0, 0, 200, 50)) label.backgroundColor = UIColor.greenColor() label.text = "I am a label" label.setTranslatesAutoresizingMaskIntoConstraints

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

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 12:11:51
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 least not what you'd expect). There is currently no alternative or replacement. Graphs are only displayed

No such module 'Cocoa' in Swift Playground

末鹿安然 提交于 2019-11-30 10:56:56
问题 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. 回答1: 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

How To Get CoreML In Pure Playground Files

我怕爱的太早我们不能终老 提交于 2019-11-30 09:54:19
问题 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? 回答1: The compiler

Swift iOS playground: Error sending deferral props

人走茶凉 提交于 2019-11-30 08:13:23
With an iOS playground set up as simply as this: import UIKit import SpriteKit import XCPlayground let s = CGSize(width: 300, height: 300) let f = CGRect(origin: CGPointZero, size: s) let view = SKView(frame: f) let scene = SKScene(size: s) scene.backgroundColor = SKColor.redColor() view.presentScene(scene) XCPShowView("main view", view) I'm getting this in the console: 2014-09-04 17:02:13.358 SpriteKitBETA7[2009:20695] Error sending deferral props: 0x10000003 There IS a "main view" box in the Assistant Editor thing, but it doesn't display anything. This exact same code (with import Cocoa

How do you instantiate a Storyboard from a file within an iOS playground?

我只是一个虾纸丫 提交于 2019-11-30 07:03:00
Let's assume you've copied a Main.storyboard from an Xcode 6 project into a standalone playground's Resources directory. How can you instantiate a UIStoryboard using the Main.storyboard file? Trying to use the default via nil doesn't work: let storyboard = UIStoryboard(name: "Main", bundle: nil) Nor does explicitly using the main bundle: let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) Even if the playground is part of the storyboard's Xcode project, I receive the same error: "Could not find a storyboard named 'main' in bundle NSBundle..." Seems that the bundle path