天道酬勤,学无止境

swift-playground

Transition PageCurl to Scroll with UIPageViewController

Question I would like to change my animation between the view. Currently i have the PageCurl but i would like to have a Scroll animation like Snapchat. I can not use the var transitionStyle: UIPageViewControllerTransitionStyle { get } My ViewController : import UIKit class ViewController: UIPageViewController, UIPageViewControllerDataSource{ let pageViewController = UIPageViewController(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil) var messagesViewController : MessagesViewController! var searchViewController : SearchViewController! var friendsViewController

2022-05-10 01:47:05    分类:技术分享    ios   swift   xcode6   uipageviewcontroller   swift-playground

How to setup ViewController in Playgrounds?

Question In swift playgrounds how do you setup a viewcontroller and use it? I've done it with a UIView before but the UI gets cut when in a difference orientation so I want to try use a viewcontroller. I've got let view = UIViewController() but after that how do I set it up to add a background and stuff on it? Answer1 To create a view controller in a Swift playground you need this code: import UIKit import PlaygroundSupport class ViewController: UIViewController{ override func viewDidLoad() { super.viewDidLoad() // do setup here } } let viewController = ViewController() PlaygroundPage.current

2022-05-01 07:13:13    分类:技术分享    swift   xcode   uiviewcontroller   swift-playground

How to get a Canvas in a Swift Playground

Question 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. Answer1 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: CGFloat = 375.0 let containerCenter: CGPoint = CGPoint(x: (containerWidth/2), y:

2022-04-26 00:56:16    分类:技术分享    xcode   swift   swift-playground

Mouse events (NSTrackingArea) in Playground not working

Question I have a a subclass of NSView which contains the following NSTrackingArea code. But for some reason the mouse events won't trigger in Playground. The viewWillMoveToWindowis being called, but nothing else seems to fire. Does anyone have a clue to what is missing? class MyView: NSView { private var trackingArea: NSTrackingArea = NSTrackingArea() // Other stuff omitted here... // ... override func viewWillMoveToWindow(newWindow: NSWindow?) { // Setup a new tracking area when the view is added to the window. trackingArea = NSTrackingArea(rect: self.bounds, options: [.MouseEnteredAndExited

2022-04-23 19:18:58    分类:技术分享    xcode   swift   swift-playground

Xcode 7 Playground execution EXC_BAD_ACCESS

Question Running the simplest, default code in Xcode 7 playgrounds... get the following error Playground execution failed: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x8). * thread #1: tid = 0x351bc3, 0x00000001062019ca libicucore.A.dylib`utext_clone + 22, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8) * frame #0: 0x00000001062019ca libicucore.A.dylib`utext_clone + 22 frame #1: 0x000000010633ac42 libicucore.A.dylib`icu::RegexMatcher::reset(UText*) + 54 frame #2: 0x0000000106375414 libicucore.A.dylib`uregex_setText + 222 frame #3

2022-04-21 15:54:04    分类:技术分享    swift-playground   xcode7

Bug in Swift array subscript indexing?

Question I've isolated some Swift code from my project that can be pasted into a Playground. It produces an error "Could not find an overload for '+' that accepts the supplied arguments" both in normal Xcode editing and the Playground. The error refers to the last (non-trivial) line. import UIKit let points = 40 let max = points-1 let L = 10.0 let Deltat = 0.01 let Deltax = L/Double(points) var a = [Double](count: points, repeatedValue: 0.0) var b = [Double](count: points, repeatedValue: 0.0) var c = [Double](count: points, repeatedValue: 0.0) for i in 1..<max-1 { //let iPlus1 = i+1 //let temp

2022-04-19 05:35:08    分类:技术分享    ios   arrays   swift   swift-playground   subscript-operator

Swift playground execution speed

Question Is there a way to increase execution speed of a playground? I want to iterate many cycles and not to wait 10 minutes. For example: import UIKit var count = 0 for var i = 0; i < 1000000000; i++ { count++ } This code will execute a way too long. But I want to get quick result. Answer1 One of the biggest performance killer is the output at the right side of the playground. Now I will show you how to minimize this output. See at the end for your example code. Best Performance The most performant way is to make all the performance critical code in a .swift file inside the Sources folder in

2022-04-16 20:09:04    分类:技术分享    ios   swift   swift-playground

Swift Playground XCPShowView "Unable to satisfy constraints"

Question I'm trying to get a Live View to show a simple animation in a Swift Playground. Whenever I import the XCPlayground framework to execute the XCPShowView function i get this error: Playground execution failed: error: Couldn't lookup symbols:_CGPointMake The error changes for a few other "symbols" as well, including CGRectMake. After being advised to modifying my code to remove the "make" from methods such as CGRectMake I still get an error from Xcode when I try to animate my view. The error message is really long, but basically it says "Unable to simultaneously satisfy constraints

2022-04-16 12:38:27    分类:技术分享    animation   swift-playground

Xcode freezes when trying to execute this in a Swift playground?

Question I was simply experimenting with Swift, so I threw together this in my playground: // Playground - noun: a place where people can play import Cocoa func printCarInfo(car:Car?) -> Void { if let _car = car { println("This is a " + _car.make + " " + _car.model + " from \(_car.year). It's worth $" + _car.price + ".") } } class Car { init(make:String, model:String, year:UInt, color:NSColor, price:UInt) { self.make = make self.model = model self.year = year self.color = color self.price = price } var make : String var model : String var year : UInt var color : NSColor var price : UInt func

2022-04-16 12:05:28    分类:技术分享    xcode   swift   freeze   swift-playground

Xcode 6 Beta / Swift - Playground not updating

Question 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

2022-04-16 02:32:29    分类:技术分享    swift   xcode6   swift-playground