How do you instantiate a Storyboard from a file within an iOS playground?
I found this:
"You can throw a xib file into your Resources, but the playground cannot read it or run it because it’s not in compiled form. Today, I (finallly!) thought of using ibtool to pre-compile my MainMenu.xib file into nib and then load that. When you install Xcode’s command line tools, ibtool gets added to /usr/bin. So all you need to do to compile your nib is issue the following command:
ibtool --compile MainMenu.nib MainMenu.xib`
Throw that resulting nib into your playground’s resources folder and you’re ready to load it up."
at http://ericasadun.com/2015/03/25/swift-todays-wow-moment-adding-menus-to-playgrounds/
Your storyboard will be compiled into multiple nibs (one per scene)
Hope it helps
Is it possible to load a storyboard in an iOS Playground?
Your storyboard init code works for me if I set up the resource section of the playground with the same structure as an app.
Resources->Base.lproj->Main.storyboardc
Swift playgrounds with UIImage
- Open the .playground file in Finder.
- Create a folder called Resources next to it.
- Add any images you want to this folder.
- In the playground press opt-cmd-1 to open the File Inspector. You should see the playground on the right. If you don't have it selected, press cmd-1 to open the Project Navigator and click on the playground file.
- Under 'Resource Path' choose 'Relative To Playground'
- Click the folder icon underneath and choose the Resources folder created earlier.
You should now have a bundle that you can use with the standard NSImage(named:"filename_without_extension"):
Note: Because Xcode will frequently overwrite the .playground folder, I recommend using this method so the resources folder isn't getting constantly deleted and re-created.
How can I build an application using only a Swift playground?
You cannot use storyboards directly in a playground, which is why Xcode doesn't support creating a storyboard inside of a playground. You can access a framework from a storyboard inside of a workspace (including cocoapods), so one solution is to make a framework to load your storyboards. This doesn't seem to fit with your criteria of making everything in playgrounds though. So you can either make all of your view programmatically or you can drag in compiled nib files to your Playground Resources folder and load the nibs from there (the playground cannot load xib, which is the XML representation of the nib).
I'm not finding the path of storyboards
Usually you can find your storyboard / storyboards in the folder Base.lproj
Details:
In Xcode 5 and later, base internationalization is enabled by default.
Xcode creates a Base.lproj
folder in your project folder and adds to it the resource files you select. Xcode creates a language folder for the development language but only adds resources that need translation to the folder. For example, if you select English as the development language, Xcode inserts the resource file in the Base.lproj project folder but not the en.lproj folder because the resource is already in English.
Related Topics
Swift 3 Get Start Index (As Int) of Substring
Include an Extension for a Class Only If iOS11 Is Available
Lazy Readonly Property in Swift
What Is an Example of Drawing Custom Nodes with Vertices in Swift Scenekit
How to Determine If a Variable Passed in Is Reference Type or Value Type
Cannot Assign to Value: 'Word' Is a 'Let' Constant
Checking When a Date Has Passed - Swift
Swift String VS. String! VS. String
Get Index in Foreach in Swiftui
Filter by Multiple Array Conditions
Simple Clickable Link in Cocoa and Swift
How to Make Rounded Corner Progress Bar in Swift
Mkpointannotations Touch Event in Swift
Handle Swiftui and Corelocation with Mvvm-Pattern