Skip to main content
AppleVis

Main navigation

  • Apps
  • Forum
  • Blog
    • Podcast
    • Guides
    • Hardware & Accessory Reviews
    • Bug Tracker
    • Developer Resources
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. App Development and Programming

Making Swift Playgrounds accessible

By robin24, 30 November, 2014

Forum
App Development and Programming

Hi all!
I just made an interesting observation, and thought it might help some of you.
As you might now, Apple introduced 'Playgrounds' in Xcode 6, which make it possible to run Swift code without having to compile it first. When I tested this out, I found that I could write code within a Playground, however I wouldn't be able to see any results using VO. At first I thought that this was simply inaccessible, but in fact this is not the case! Instead, I learned today that the Assistant Editor has to be visible in order to see the output of code. In order to make this visible in Xcode within a Playground, do this:
1. Create a Playground in Xcode or open an existing one.
2. Once you get to the editor, go to the menu bar by pressing VO+M and select the 'View' column.
3. Once you get there, press down arrow until you get to the 'Assistant Editor' sub menu.
4. Press enter to open the 'Assistant Editor' sub menu, and then select the 'Show Assistant Editor' option.

Once the Assistant Editor has been enabled and you stop interacting with the source code editor, you can press VO + right arrow to get to the Assistant Editor group. Interacting with this will reveal reveal a 'Console Output' text field, where the program's text output will be shown. For instance, a line of code like

println("Hello world!")

will show the text "Hello world!" on the screen. Furthermore, errors will also be shown here. Consider the following code:

import Cocoa

let myName = "John"
println("Hey there, my name is \(myName)!")
myName = "Robin"
println("Actually, my name is \(myName)...")

This will show the following error:

Playground execution failed: /var/folders/6f/5xnnw4px0m90_yz1vjd0jysh0000gn/T/lldb/13681/playground140.swift:7:8: error: cannot assign to 'let' value 'myName'
myName = "Robin"
~~~~~~ ^

This is because a constant (declared by using the 'let' keyword) cannot be assigned another value, and thus execution fails as can be seen by the error message. I find this better than navigating the 'Issue Navigator' within a complete Xcode project...
I hope this will help some of you! :-)
All the best,
Robin

Options

  • Log in or register to post comments

Comments

Thank you

By Mani

6 years 8 months ago

I am trying to learn Swift and this was the first hurdle I came across. I chanced upon this post when I googled for a solution. Thank you so much, robin24.

More Like This

Looking for one on one online class on Swift 3 development (Forum Topic)
Xcode: connecting interface elements to each other (Forum Topic)
Help Me Learn Swift + Towers of Hanoi (Forum Topic)
Program for reading PDF files (Forum Topic)
Swift Playgrounds (Forum Topic)
Connecting Storyboard elements to code (Forum Topic)
Download swift playgrounds (Forum Topic)
Swift Playgrounds On The Mac (Forum Topic)

Site Information

  • About
  • Club AppleVis
  • FAQ
  • Contact

Unless stated otherwise, all content is copyright AppleVis. All rights reserved. © 2023 | Accessibility | Terms | Privacy