swift-playground

Xcode 6 Beta / Swift - Playground not updating

我的未来我决定 提交于 2019-12-04 17:40:48
问题 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

Playground in Swift won't use Firebase

时光总嘲笑我的痴心妄想 提交于 2019-12-04 14:01:57
As u probably all might know Firebase made a Version jump and I am trying to get my setup working with the Xcode Playground. There is a reference how to implement Firebase in Playground with older versions of Cocoapods and Ruby but that won't really work for me swift playground for experimenting with firebase . Even though Firebase implementation in the Project itself works fine and i can import my Firebase it won't work on a Playground any more. Does somebody know how to add a working setup with a Playground and Firebase? Software in use: Cocoapods: 2.6.4 Pod: 1.0 Xcode: 7.3.1 Firebase: 3.2.0

Swift: Overriding didSet results in a recursion

核能气质少年 提交于 2019-12-04 10:36:53
问题 When overriding the didSet observer of a property results in recursion, why? class TwiceInt { var value:Int = 0 { didSet { value *= 2 } } } class QuadInt : TwiceInt { override var value:Int { didSet { value *= 4 } } } let t = TwiceInt() t.value = 5 // this works fine let q = QuadInt() q.value = 5 // this ends up in recursion If I update the QuadInt with class QuadInt : TwiceInt { override var value:Int { didSet { super.value *= 4 } } } q.value = 5 // q.value = 80 So I guess the call to be

Transition PageCurl to Scroll with UIPageViewController

霸气de小男生 提交于 2019-12-04 07:13:00
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 :

DispatchWorkItem not notifying main thread

浪尽此生 提交于 2019-12-04 06:25:45
问题 Note: This is not duplicate question I have already seen Dispatch group - cannot notify to main thread There is nothing answered about DispatchWorkItem I have code like below let dwi3 = DispatchWorkItem { print("start DispatchWorkItem \(Thread.isMainThread)") sleep(2) print("end DispatchWorkItem") } let myDq = DispatchQueue(label: "A custom dispatch queue") dwi3.notify(queue: myDq) { print("notify") } DispatchQueue.global().async(execute: dwi3) Which is working correctly (I can see notify on

How to use a custom framework with a playground in Xcode 9

元气小坏坏 提交于 2019-12-04 05:17:04
I am trying to use a custom framework in a playground as described in this Apple documentation: http://help.apple.com/xcode/mac/9.0/#/devc9b33111c However, I am unable to get the playground to recognize the framework ( https://github.com/gk-brown/MarkupKit ). It is a 64-bit Objective-C framework that defines a module. Here is what I have tried: Create a new "single view" playground As directed in the document, open the playground and choose File > Save As Workspace Close the playground Open the workspace containing the playground Attempt to choose File > Add Files to [Workspace Name] The menu

Rename default rendered headings like “Example” in Swift Markup language

微笑、不失礼 提交于 2019-12-04 04:01:35
Raw Markup Rendered Markup How do I change the word Example in the "Rendered Markup" to anything I would like? Custom callouts You can make use of a Custom Callout /*: # Hello, playground! The print() function in Swift * callout(Custom Title): print("Hello, playground!") */ Rendered as (using Dusk theme) Additional pre-defined callouts If you don't fancy the color of the Custom Callout, there are a few other callouts (in addition to Example) available for use in a playground /*: # Hello, playground! The print() function in Swift * Example: print("Hello, playground!") * Experiment: print("Hello

Consonants and Vowels Swift

流过昼夜 提交于 2019-12-04 02:42:43
问题 I'm new at Swift, could anyone explain to me why I'm keep getting this problem. I'm using Xcode 6.4, but here is my question I hope I cleared it up but I needed my Function to takes in Large String then returns Tuple(numVowels, numConsonants) Count the number of words that start with consonants/vowels Return the Tuple and print the result of the function call. I did not need for it to count characters, only first character of each word. I create an for loop which will switch everything to

Does iOS Playgrounds supports UIView animations?

旧时模样 提交于 2019-12-03 23:39:32
Is it possible to preview animation done for UIView with animateWithDuration in Playground? I am adding XCPShowView right after initialization of UIView and its shows everything it in a final state no matter what position on a timeline I will choose. lazi74 Xcode 7 update : XCPShowView is deprecated but you can see the animation in the playground liveView. And there is more coming soon: Interactive Playgrounds Here is an update to Joseph Chen sample code. I also changed the color to green as the container default background is black : import UIKit import XCPlayground let container = UIView

Access properties via subscripting in Swift

前提是你 提交于 2019-12-03 23:39:17
问题 I have a custom class in Swift and I'd like to use subscripting to access its properties, is this possible? What I want is something like this: class User { var name: String var title: String subscript(key: String) -> String { // Something here return // Return the property that matches the key… } init(name: String, title: String) { self.name = name self.title = title } } myUser = User(name: "Bob", title: "Superboss") myUser["name"] // "Bob" Update: The reason why I'm looking for this is that