I just upgraded to Xcode 6.3 and they offered something new to the Playgrounds. If you make a new playgrounds and you open the project navigator, you will see a Sources folder and inside that there is a "SupportCode.swift" file. At the top of that file it reads
This file (and all other Swift source files in the Sources directory of this playground) will be precompiled into a framework which is automatically made available to .playground.
I tried putting a function in to there and it is not available to my playground. What am I doing wrong? Do I have to manually compile the SupportCode.swift file manually? How?
Xcode and Swift are both software development products developed by Apple. Swift is a programming language used to create apps for iOS, macOS, tvOS, and watchOS. Xcode is an Integrated Development Environment (IDE) that comes with a set of tools that helps you build Apple-related apps.
Restarting Xcode and rebooting my macbook. Stopping the simulator via the Activity monitor and restarting it. Opening up new tabs in an attempt to refresh. Uninstalling and reinstalling Xcode via the app store.
You have to add public access attribute to your classes, methods and properties in source folder to make them accessible from main playground file as they treated as separate module by compiler
Playgrounds are good for running tests. Put all your code in the Sources
directory and have one publicly accessible 'test' class, for each test. Then run the publicly accessible tests from the playground.
playground
Test1.run() Testx.run() ...
Sources/Test1.swift
public class Test1 { public static func run() { let my_class = MyClass() let result = my_class.do_something() print(result) } }
Sources/MyClass.swift
class MyClass { func do_something() -> String { return "lol" } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With