Questions tagged [swift-playground]

0

votes
0

answer
3

Views

Is markup formatting just for Swift playgrounds?

In swift file, I don’t see editor _ show rendered markup button. For example. //: - Experiment: //: Modify the anyCommonElements(_:_:) function to make a function that returns an array of the elements that any two sequences have in common. //: How can I show this in rendered markup mode in swift f...
John
1

votes
0

answer
267

Views

Swift playground isn't sandboxed

I am looking for more information on how macOS Swift Playgrounds handle sandboxing. I'd like to test how some macOS code runs inside a sandbox, but from what I'm seeing, the Playground isn't sandboxed, at least for macOS. https://stackoverflow.com/a/38987133/2778502 says that iOS playgrounds are san...
jeff-h
1

votes
2

answer
201

Views

Swift 3 - Function for Wrapping an Array

As I try to learn Swift 3, I am attempting to 'Wrap an Array of Elements'. In Swift 3 Playgrounds, I was able to implement code that wraps an array. My problem occurs when I try to create a function that implements my code. If you take the following code and copy-paste it to a Swift 3 Playground the...
1

votes
1

answer
385

Views

How to make an Xcode playground rotate to landscape

I am trying to test a landscape view, but so far I cannot make progress. My code looks like this: import UIKit import PlaygroundSupport class MyViewController : UIViewController { override func loadView() { let view = UIView() view.backgroundColor = .white let label = UILabel() label.text = 'Hallo'...
Coti Garcia Bermejo
1

votes
0

answer
145

Views

EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) in xcode playground

I am trying to create a collection view class for my playground. I have this code. It is a class when I create a UICollectionView in Xcode playground to after it will use in my principal file. This is my code: import UIKit import SceneKit public class MenuCollectionView: UICollectionView, UICollecti...
E5SC
1

votes
0

answer
191

Views

How to center my Playgrounds Live View

I am instantiating a playground live view using the following code: import UIKit import PlaygroundSupport let view = UIView() view.frame = CGRect(x: 0, y: 0, width: 100, height: 100) view.backgroundColor = .white PlaygroundPage.current.liveView = view The live view that appears is stuck to the top o...
omranK
1

votes
0

answer
53

Views

Animating Image Graphics Context Swift

I currently have this code, which lets me create a spirograph using Image Graphics Context: func generateSpirograph(insideRadius: Double = 0.5, rotationalSpeed: Double = -31/3, color: UIColor = .blue) { //Creates an 800*800 image that is transparent guard let transparentImage = UIImage(named: 'trans...
Pablo Zilly
1

votes
1

answer
545

Views

How To Get CoreML In Pure Playground Files

I am using a .playground file and I can't seem to add my CoreML model to it. I drag it into the Resources folder and this is my code: func predict(image: CGImage) { let model = try! VNCoreMLModel(for: Inceptionv3().model) let request = VNCoreMLRequest(model: model, completionHandler: results) let ha...
SaiK1065
1

votes
0

answer
80

Views

How to auto-layout view in Playground LiveView

I have a Live View and a view on which I work on, and I would like this last one to resize according to LiveView dimensions (i.e.: in portrait the LiveView occupies only the top-half of the screen, in landscape only the right-half). I read that NSLayoutCostraints don't work in playground, so how sho...
Garu94
1

votes
2

answer
937

Views

How do I get the .mlmodel to be used in Swift Playground?

I have already converted the .mlmodel to .mlmodelc , and I have put it in the resources folder. Im using Vision framework and MNIST model, following this tutorial (https://www.youtube.com/watch?v=bOg8AZSFvOc), but using swift playground. What am i missing? (im using .playground files, not .playgrou...
Jazz Ooi
1

votes
0

answer
235

Views

How to access classes from different playground pages in playground?

I'm currently working on a single view playground. At this point, my main playground file has a bunch of view controller classes and is really disorganized. Im trying to reorganize my code by splitting up the view controller classes into separate playground files like how you would with a project. I...
leedex
1

votes
1

answer
116

Views

How can I hide the keyboard in the UI in Swift Playgrounds (on Xcode) that appears in the Live View when I create a UITextView?

I have created a UITextView object and when I interact with it in the Live View, the keyboard appears in the UI and the only way to enter text seems to be from that keyboard. Is this a recent change in Swift Playgrounds? Is there any way users can enter text from their physical keyboards? Code: let...
Harshita Arora
1

votes
1

answer
73

Views

Close Button Not Working in Swift Playground

I am working on a Swift playground for WWDC. I need to have a UI Button that closes the web view and toolbars (the button is called closeButton and the function is at the bottom for the button), and returns to the previously screen when clicked (the first view). The code below is the Swift I have ty...
Mark_Bruckert
1

votes
1

answer
162

Views

Swift playground error: extra argument 'timeout' in call

I'm trying to run this code in playground: //: Playground - noun: a place where people can play import UIKit import XCTest // Create an expectation for a background download task. let expectation = XCTestExpectation(description: 'Download apple.com home page') // Create a URL for a web page to be do...
poima
1

votes
0

answer
44

Views

Why does Swift Playgrounds return an error when trying to load in an image for a SKSpriteNode object?

I am currently making a game with Swift Playgrounds for the iOS platform. However, I am having troubling loading in image data for an SKSpriteNode. I would set it as a SKTexture: DoctorBrown.texture = SKTexture(imageNamed: 'WelcomeToTheDelorean') It used to work fine, but now it doesn't (not sure wh...
John Doe
1

votes
1

answer
140

Views

Use database on Swift playgrounds (iOS)

Is there any way to connect some of my iOS Playgrounds to Firebase or any other database? I have really enjoyed Swift Playgrounds, I have playgrounds with more than 2 thousand of lines fetching json, html, web images and txt files and I use uikit and SceneKit. So I want to see if there is any way to...
1

votes
0

answer
64

Views

Xcode 10.1 single view playground template displays as empty black view

I'm trying to use a Swift playground to prototype some simple drawing code. Starting with the single view iOS template: //: A UIKit based Playground for presenting user interface import UIKit import PlaygroundSupport class MyViewController : UIViewController { override func loadView() { let view = U...
Chris
0

votes
1

answer
1.9k

Views

Swift Playground - “Use of unresolved identifier 'myClass'” but still compiles

I am currently experimenting in Swift Playgrounds, and am trying out SpriteKit. My playground is working as expected, and runs, but Xcode has an error saying 'Use of unresolved identifier 'myClass''. The playground still runs perfectly still though. Here is my code: import UIKit import PlaygroundSup...
William Taylor
1

votes
0

answer
61

Views

Xcode - Change Default Playground Save Location

Is there a way to change where Xcode automatically suggests to save a Playground? Whenever I create one the default location is a folder names 'Autosave Information', which is automatically created and of which there are several. I've often 'lost' playgrounds in there, and would love for the system...
IcarusTyler
1

votes
1

answer
47

Views

Use AVFoundation's Recorder on iOS Playground, but recorder.record() always returns false

Is there anyway to use recorder on iOS Playground? When running, it asks my permission to use my microphone, and the recorder instance seems working, however, I can't use the record() function. My current environments are iOS 12.1.4 and Swift 4.2. import UIKit import PlaygroundSupport import AVFound...
Race Li
1

votes
1

answer
62

Views

I can't import AudioKit or AudioKitPlaygrounds in swift Playground file

AudioKit beginner and I really need some help here! I want to track the frequency and amplitude of a selected audio file in swift language using playground on my Mac. I searched that AudioKit is particularly easy in tracking the frequency and the amplitude, but after downloading AudioKit framework o...
Jack Stark
1

votes
1

answer
59

Views

Method renderer(_:didAdd node:, for anchor:) not called

I try to implement plane detection in my AR experience. I have a subclass of ARSCNView with an ARSCNViewDelegate extension. My cameraDidChangeTrackingState delegate method is called. However, I've never ONCE see my renderer(_:didAdd node:, for anchor:) method being called. Any idea? class ARView: AR...
thisIsTheFoxe
1

votes
0

answer
82

Views

How to access camera in Mac OS Mojave Swift playground

How to access the camera in Swift playgrounds on Mac OS Mojave? This used to work with no problem on High Sierra however the code does not seem to execute correctly any more as the playgrounds running symbol is spinning continuously as well as the camera lights staying off. I got an example of the c...
Ferdinand Lösch
1

votes
0

answer
27

Views

Positioning shape at the edge of the screen

Given a PlaygroundBook page, how can you position a SpriteKit node to the right edge of the screen of the liveView so it 'snaps' there? So far I've tried to position the node like so: // Context: class _: SKScene // myNode.frame.size == CGSize(width: self.frame.width / 4, height: self.frame.height...
Fehniix
1

votes
0

answer
32

Views

Implementation of placeholder tokens

It seems that the standard Apple implementation of the Placeholder Tokens (to show a custom slider popover for integer values) for Playground Books just doesn't work. Pasting Apple's code results in this, in Xcode: var typedLlamaCount = /*#-editable-code*//*#-end-editable-code*/ Has anybody ever s...
Fehniix
1

votes
1

answer
702

Views

playground does not track the uiimage

I am working with xcode 6, and I am recreating the image code that was demoed during session 401 'what is new in xcode 6). I put an image in my Bundle resource directory, and created a playground file. Playground does not execute the command var sample = UIImage(named: 'img') or any command after. A...
ehassan2014
1

votes
1

answer
1.8k

Views

Converting NSString to CString in Xcode Playground

When I attempt: import Cocoa var ns: NSString = 'whatever' var cs: CString = ns.UTF8String println(cs) in an Playground it reports this exception when executing the var cs: CString = ns.UTF8String statement: fatal error: Can't unwrap Optional.None Playground execution failed: error: Execution was in...
darrinm
1

votes
1

answer
58

Views

Swift Playground: Indexing a List within a class gives an error

I tried the following in Swift Playground: class C { init(test: Integer) { let simpleList:String[] = ['A','B','C'] simpleList[test] println(simpleList[test]) } } I get an error: Could not find an overload for subscript that accepts the supplied arguments This pops up in multiple places when I try t...
arvind
1

votes
1

answer
454

Views

Set the default text color for “Value History” and “Quick Look” for Playground on XCode

I have been trying to find a way to set the default text color for 'Value History' and 'Quick Look' for Playground on XCode. But, I couldn't find any settings for that. The below screen shot shows both the text color and also the background color for 'Value History' and 'Quick Look' are white. I cou...
Ricky
1

votes
1

answer
352

Views

Runtime for selected device error in playground

I am working in the Playground. I accidentally was using OSX playgrounds instead of iOS Playgrounds, so I opened a new Playground for iOS. When I opened the Playground I immediately got this error: 'The runtime for the selected device is not installed.' This error pops up every time I try to type an...
Janie Larson
1

votes
2

answer
149

Views

What about this code causes swift to crash?

I'm playing around with arrays and a flatten function in order to wrap my head around how Swift uses generics. However, the following code gives a generic 'Error running playground' popup, and I can't work out why. Interestingly, if I put the code into a project and try to compile it, the compiler s...
sapi
1

votes
1

answer
142

Views

Swift: Order of super.init and self.attribute in init

I'm trying to init a subclass like the following: class NameShape{ var numberOfSide: Int = 0 var name:String func simpleDescription() -> String { return 'A square with \(numberOfSide) sides.' } init (name: String){ self.name = name } } class Square:NameShape{ var sideLength: Double init(name: String...
user2988464
1

votes
1

answer
389

Views

Swift gives me an error message in console for println

I started to learn swift same as using MAC_OS, here is what playground says when i try to 'println' any string. I understand it's beta, but still may be somebody already resolved this problem. Thank you. Unable to create symlink at /Users/macbook/Library/Containers/com.apple.dt.playground.stub.OSX.p...
Balan Anastasia
1

votes
1

answer
922

Views

Develop chart control using an xcode playground for iOS

I would like to experiment with building a simple but unique chart control for my iOS app with the new playground feature of xcode for iOS. However, I am struggling to get started using playground to create a uiview and use core fraphics . I can see a few examples for Mac osx using nsview but failed...
ConfusedNoob
1

votes
2

answer
797

Views

No such module 'Cocoa' in Swift Playground with OS X platform

I use xcode 6.1 in normal but it gets a error suddenly. It should import the Cocoa framework with OS X platform: import Cocoa And it has this problem with OS X platform only.
Susan Doggie
1

votes
1

answer
139

Views

Making NSNull conform to NilLiteralConvertible

I'm trying to make NSNull conform to NilLiteralConvertible, but I'm running into an enormous amount of frustration: extension NSNull : NilLiteralConvertible{ required convenience init(nilLiteral: ()){ self.init() } } First of all, I'm forced to make the init a convenience one, as I can't add designa...
cfischer
0

votes
0

answer
4

Views

MacOS Playground: How can change the background color?

I'm trying to change the background color of main view: import AppKit import PlaygroundSupport class ViewController : NSViewController { override func loadView() { let nibFile = NSNib.Name('MyView') var topLevelObjects : NSArray? Bundle.main.loadNibNamed( nibFile, owner:nil, topLevelObjects: &topLev...
user2924482
1

votes
1

answer
189

Views

Specific letters that have each specific colors?

I'm wondering if there is a way to make letters in every word colored using the Swift programming language. I'm looking for ideas and leads. Example: println('This is a string') would look like this: Just incase this helps, I have found other languages that are capable of coloring each letter speci...
dnaatwork.com
1

votes
1

answer
116

Views

Method in an enum is asking for argument when none required in declaration

This maybe a terrible n00b question but I'm finally getting to look at Swift properly. Imagine I have a simple enum representing a playing card. In it I have a method that returns an Array of Cards. The method has no arguments, but when I call it the auto-completion and compiler both state it needs...
Cocoadelica
1

votes
1

answer
839

Views

Xcode playground and initialize NSImage

I'm coding with Xcode playground but I got error at the first line of my code: import Cocoa import XCPlayground let image = NSImage(size: NSSize(width: 100, height: 100)) With initialising image a got two errors: ImageIO: CGImageDestinationFinalize image destination must have at least one image CGIm...
pravdomil

View additional questions