swift-playground

Swift Playgrounds not updating automatically on macOS [duplicate]

你。 提交于 2020-01-11 13:09:56
问题 This question already has answers here : Xcode: Any way to refresh/re-run the playground? (7 answers) Closed 2 years ago . I have several Swift playgrounds on my machine that aren't updating automatically. I can manually select "Run Playground" from the Editor menu, which runs what's in the playground at that time, but it never updates when I type new code. I've tried clearing the compilation cache in "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache" , restarting Xcode,

How to return a first word from a string in Swift?

僤鯓⒐⒋嵵緔 提交于 2020-01-09 08:09:29
问题 If we have, for example, situation like this: var myString = "Today was a good day" What is the best way to return the first word, which is "Today"? I think mapping should be applied, but not sure how. Thanks. 回答1: The simplest way I can think of is Swift 3 let string = "hello world" let firstWord = string.components(separatedBy: " ").first Swift 2.2 let string = "hello world" let firstWord = string.componentsSeparatedByString(" ").first and if you think you need to use it a lot in your code,

How to return a first word from a string in Swift?

大城市里の小女人 提交于 2020-01-09 08:09:13
问题 If we have, for example, situation like this: var myString = "Today was a good day" What is the best way to return the first word, which is "Today"? I think mapping should be applied, but not sure how. Thanks. 回答1: The simplest way I can think of is Swift 3 let string = "hello world" let firstWord = string.components(separatedBy: " ").first Swift 2.2 let string = "hello world" let firstWord = string.componentsSeparatedByString(" ").first and if you think you need to use it a lot in your code,

Class 'ViewController' has no initializers in swift

家住魔仙堡 提交于 2020-01-09 07:04:07
问题 Getting the complaint from the compiler when I am doing this class ViewController: UIViewController { var delegate : AppDelegate override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. //self.appDelegate = UIApplication.sharedApplication().delegate; } @IBAction func getData(sender : AnyObject) { } @IBAction func LogOut(sender : AnyObject) { } } However, if I just add ? at the end of AppDelegate like below and the error is gone

What about this code causes swift to crash?

和自甴很熟 提交于 2020-01-06 01:58:27
问题 I'm playing around with arrays and a flatten function in order to wrap my head around how Swift uses generics. However, the following code gives a generic 'Error running playground' popup, and I can't work out why. Interestingly, if I put the code into a project and try to compile it, the compiler segfaults. import Cocoa var arr: [[Int]] = [[1,2], [3,4], [5,6]] func flatten<S: SequenceType, SS: SequenceType, E where S.Generator.Element == SS, SS.Generator.Element == E>(seq: S) -> [E] { var

How to add a UIButton to Swift Playground?

耗尽温柔 提交于 2020-01-04 01:53:29
问题 So I opened up playground, I just want to add a simple UIButton (or a simple UIView) for testing purposes. I can't get it to display though. This is what I have so far: import UIKit var uiButton = UIButton.buttonWithType(UIButtonType.System) as UIButton uiButton.frame = CGRectMake(0, 0, 100, 100) uiButton.setTitle("Test", forState: UIControlState.Normal); //self.view.addSubview(uiButton) <-- doesn't work Do you guys know what I'm doing wrong? Thanks 回答1: I think you can add button into

Swift playground with debugger support?

≡放荡痞女 提交于 2020-01-03 19:01:35
问题 Swift playgrounds in Xcode 7 don't seem to support usage of the debugger. This features seems like it would be (extremely) useful ... I've got a playground that exercises code within a framework I'm writing. I'd really love to be able to set a breakpoint on the code within my framework -- and have the debugger stop execution when the breakpoint is hit when the code is executed from a playground. Does anyone know why playgrounds don't currently support this? Is there some fundamental reason

Import Kanna in playground

▼魔方 西西 提交于 2020-01-02 10:03:54
问题 Is there a way to add Kanna (https://github.com/tid-kijyun/Kanna) to Playground in XCode? I have tried to install it manually and via CocoaPods, but with no luck. I have also tried to pack it inside a Framework, but still no luck. Would appreciate any input. These are the error messages I am most often encountering: 回答1: There is an interesting library in Github that allows run pods in Playground.It's still so young but it's very good. It's create a new project with the pod or pods installed

XCode 6 GM: Constantly freezing / locking while editing Swift code

 ̄綄美尐妖づ 提交于 2019-12-30 20:30:00
问题 Since installing XCode 6 GM, it has been freezing and locking, showing the spinning wheel of death while I attempt to edit code that has syntax errors. Has anyone else seen this, and are there any known work-arounds? I foolishly abandoned my cautious strategy of saving the previous version (Beta 7) and it appears that Beta 7 is no longer available for download. Are there any known archives of / for the link? I have also posted to the dev forums and will follow up with a bug report, but it is

XCode 6 GM: Constantly freezing / locking while editing Swift code

£可爱£侵袭症+ 提交于 2019-12-30 20:26:02
问题 Since installing XCode 6 GM, it has been freezing and locking, showing the spinning wheel of death while I attempt to edit code that has syntax errors. Has anyone else seen this, and are there any known work-arounds? I foolishly abandoned my cautious strategy of saving the previous version (Beta 7) and it appears that Beta 7 is no longer available for download. Are there any known archives of / for the link? I have also posted to the dev forums and will follow up with a bug report, but it is