swift-playground
How can I use Swift 2.3 in XCode 8 Playgrounds?
Unfortunately, according to Apple it is impossible: For instance, Playgrounds in Xcode only work with Swift 3, and notably the Swift Playgrounds app for iPad also uses Swift 3. Xcode project templates all use Swift 3, and all documentation is presented in a format appropriate for Swift 3. More here.
No such module ‘Cocoa’ in Swift Playground
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 Inspector (View→Inspectors→Show File Inspector) under Playground Settings→Platform. By … Read more
Could not find an overload for ‘/’ that accepts the supplied arguments
There are no such implicit conversions in Swift, so you’ll have to explicitly convert that yourself: average = Double(total) / Double(numbers.count) From The Swift Programming Language: “Values are never implicitly converted to another type.” (Section: A Swift Tour) But you’re now using Swift, not Objective-C, so try to think in a more functional oriented way. … Read more
How to use cocoapods with playground?
This is an old question but shows up at the top of Google. This Could Be Us But You Playing is a command line tool that creates a new Xcode playground with an integrated cocoapod. It also supports integrating multiple cocoapods at once. It’s a single command. To Install: gem install cocoapods-playgrounds To Use: pod … Read more
Making my function calculate average of array Swift
You should use the reduce method to sum your sequence elements as follow: Xcode Xcode 10.2+ • Swift 5 or later extension Sequence where Element: AdditiveArithmetic { /// Returns the total sum of all elements in the sequence func sum() -> Element { reduce(.zero, +) } } extension Collection where Element: BinaryInteger { /// Returns … Read more
Playground Import: No Such Module ‘Foo’
For some of those that none of the above solutions work (and that Xcode build path setting was already set to Unique), I’ve found a solution. The framework must be built with a scheme for an iOS simulator device (any in the list) and NOT a Generic iOS Device, as Playgrounds do not support it. … Read more
Can Swift playgrounds see other source files in the same project?
There’s two ways to use your project’s code in a Playground Playground’s Sources Folder Yes, in Xcode 6.3 Beta 3 (and hopefully, into the future): Playgrounds are now represented within Xcode as a bundle with a disclosure triangle that reveals Resources and Sources folders when clicked. These folders contain additional content that is easily accessible … Read more
Iterate through a String Swift 2.0
As of Swift 2, String doesn’t conform to SequenceType. However, you can use the characters property on String. characters returns a String.CharacterView which conforms to SequenceType and so can be iterated through with a for loop: let word = “Zebra” for i in word.characters { print(i) } Alternatively, you could add an extension to String … Read more
Debug breakpoint in Swift Playground?
There’s no debugger so you can’t add any breakpoints.