Get playground to display all loop results
Right click on the inline quick look (the gray rounded rectangle with "4" in it). There's an option to show all the results in a list:
You can also show everything that's been printed to the console for the entire playground execution by clicking the show debug area button all the way in the bottom left corner:
Why is this Swift Playground Printing & Looping Twice?
Regarding override func draw(_ rect: CGRect)
This method is called when a view is first displayed or when an event
occurs that invalidates a visible part of the view.
Your line
containerView.backgroundColor = UIColor.orange
might be causing draw to get another call.
Iterating through an array only gets the first value in Swift Playground
If you're using a playground, you might need to change the view in order to see all the results..
You need to hover over the quick view display in order to find the "All Values" icon.
It looks like this may have changed in Xcode 7 - as @MikeMeyers mentions in the comments, you need to right click on the quick view window and select the value history option.
How to print to console using swift playground?
In Xcode 6.3 and later (including Xcode 7 and 8), console output appears in the Debug area at the bottom of the playground window (similar to where it appears in a project). To show it:
Menu: View > Debug Area > Show Debug Area (⌘⇧Y)
Click the middle button of the workspace-layout widget in the toolbar
Click the triangle next to the timeline at the bottom of the window
Anything that writes to the console, including Swift's print
statement (renamed from println
in Swift 2 beta) shows up there.
In earlier Xcode 6 versions (which by now you probably should be upgrading from anyway), show the Assistant editor (e.g. by clicking the little circle next to a bit in the output area). Console output appears there.
Swift troubleshooting, display data in a Xcode playground?
Are you not seeing the results printed? Sounds like you may not have the Assistant Editor open. To open the assistant editor to go View -> Assistant Editor -> Show Assistant Editor. You should get a box titled "Console Output" displaying your results.
Factorial with intermediate results - Swift playgrounds - index out of range error
results
is an empty array but you try to access values without appending values first.
The simplest solution might be to pre-populate your array with zeros.
var results: [Int] = Array(repeating: 0, count: n)
Related Topics
Show/Hide Password - How to Add This Feature
Why Are Iboutlets Optionals After Swift 5 Migration
Swift - Take Nil as Argument in Generic Function with Optional Argument
A Different Bridging Between Array and Dictionary
Variable P Passed by Reference Before Being Initialized
How to Fix ' *Pod* Does Not Support Provisioning Profiles' in Azure Devops Build Agent
Using Key-Value Programming (Kvp) with Swift
Cannot Assign to Property: 'Self' Is Immutable, I Know How to Fix But Needs Understanding
Get Path to Swift Script from Within Script
Executefetchrequest Doesn't Return the Nsmanagedobject Subclass
How to Enable Swift Support for Existing Project in Flutter
Realitykit - Set Text Programmatically of an Entity of Reality Composer
Catch Objective-C Exception in Swift
Swift, Pass Data Back from Popover to View Controller
Creating a Future Date in Swift with Nsdate()
Convincing Swift That a Function Will Never Return, Due to a Thrown Exception
How to Extract Image from Lplinkview in Linkpresentation Framework
An Nsmanagedobject of Class 'Classname' Must Have a Valid Nsentitydescription.' Error