swift-playground

16 bit logic/computer simulation in Swift

冷暖自知 提交于 2019-12-08 10:54:09
问题 I’m trying to make a basic simulation of a 16 bit computer with Swift. The computer will feature An ALU 2 registers That’s all. I have enough knowledge to create these parts visually and understand how they work, but it has become increasingly difficult to make larger components with more inputs while using my current approach. My current approach has been to wrap each component in a struct . This worked early on, but is becoming increasingly difficult to manage multiple inputs while staying

Implicitly Unwrapped Optionals and println

半腔热情 提交于 2019-12-08 08:26:37
问题 I'm learning Swift and I have a doubt regarding Implicitly Unwrapped Optionals. I have a function returning a String optional: func findApt(aptNumber :String) -> String? { let aptNumbers = ["101", "202", "303", "404"] for element in aptNumbers { if (element == aptNumber) { return aptNumber } } // END OF for LOOP return nil } and an if statement to perform safe unwrapping, which uses an Implicitly Unwrapped Optional as its constant: if let apt :String! = findApt("404") { apt println(apt)

Playground not showing results

淺唱寂寞╮ 提交于 2019-12-08 06:45:32
问题 I've got a Mac mini (early 2009) 2GB RAM. Clean installed El Capitan. Xcode 7.3 Created playground (default) but no results showing. Are there hardware requirements for playground? Thanks 回答1: Show the Debug area and Execute Playground to see resuls 来源: https://stackoverflow.com/questions/36528314/playground-not-showing-results

How Do You Debug Swift PlaygroundBook?

夙愿已清 提交于 2019-12-08 04:12:58
问题 While I'm exploring Playground Book sample code, like this one, I find it to be very tedious to get the code to run because of Playground Book's limitations in where the code can run: only on iPad's Swift Playground. There is no way to debug the "Sources" / Auxiliary code in iOS's Swift Playground, since all the source files are shown in un-editable plain text. You have to open the source files in Xcode to edit them, but then you can't compile or run them! This is especially tedious for the

How to get a UIButton to perform action in a Swift Playground

心已入冬 提交于 2019-12-08 03:30:28
问题 I am trying to use UIKit in the Swift Playground app. I can get labels and text fields working, but I can not figure out how to get a UIButton to perform an action when it is touched. import PlaygroundSupport import UIKit class MyView: UIView { //Method to be called func printname() { print ("clicked") } func buttonPressed(sender: UIButton) { print ("Here") } } func printname2() { print("button pressed") } let view = MyView() PlaygroundPage.current.liveView = view let button = UIButton(frame:

Is there a way to use Common Crypto in a Swift playground?

孤街醉人 提交于 2019-12-07 18:16:17
问题 I am toying with a REST API in an Xcode playground and I need to hash something with SHA1. All the solutions I have found depend on Common Crypto, and that doesn’t seem to be directly available in a Swift playground. Is there a way to SHA1 something in a Swift playground? 回答1: A quick and dirty solution: func SHA1HashString(string: String) -> String { let task = NSTask() task.launchPath = "/usr/bin/shasum" task.arguments = [] let inputPipe = NSPipe() inputPipe.fileHandleForWriting.writeData

What should I include in the .gitignore file for Swift playgrounds?

懵懂的女人 提交于 2019-12-06 18:04:49
问题 I want to use Git for versioning my playgrounds, but I am not sure which files should be ignored and which ones I should commit. Currently I use following .gitignore file for playgrounds: # Xcode user data xcuserdata What else should be there? 回答1: From the official github gitignore for Swift ## Playgrounds timeline.xctimeline playground.xcworkspace 回答2: Whether it is a normal project or playgrounds, it is convenient and useful to use one of the standard .gitignore files for Swift. From the

Mouse events (NSTrackingArea) in Playground not working

浪尽此生 提交于 2019-12-06 11:36:58
I have a a subclass of NSView which contains the following NSTrackingArea code. But for some reason the mouse events won't trigger in Playground. The viewWillMoveToWindow is being called, but nothing else seems to fire. Does anyone have a clue to what is missing? class MyView: NSView { private var trackingArea: NSTrackingArea = NSTrackingArea() // Other stuff omitted here... // ... override func viewWillMoveToWindow(newWindow: NSWindow?) { // Setup a new tracking area when the view is added to the window. trackingArea = NSTrackingArea(rect: self.bounds, options: [.MouseEnteredAndExited,

How to get a UIButton to perform action in a Swift Playground

大兔子大兔子 提交于 2019-12-06 09:51:02
I am trying to use UIKit in the Swift Playground app. I can get labels and text fields working, but I can not figure out how to get a UIButton to perform an action when it is touched. import PlaygroundSupport import UIKit class MyView: UIView { //Method to be called func printname() { print ("clicked") } func buttonPressed(sender: UIButton) { print ("Here") } } func printname2() { print("button pressed") } let view = MyView() PlaygroundPage.current.liveView = view let button = UIButton(frame: CGRect(x: 50, y: 100, width: 100, height: 50)) button.addTarget(view, action: #selector(MyView

Playground in Swift won't use Firebase

China☆狼群 提交于 2019-12-06 06:27:22
问题 As u probably all might know Firebase made a Version jump and I am trying to get my setup working with the Xcode Playground. There is a reference how to implement Firebase in Playground with older versions of Cocoapods and Ruby but that won't really work for me swift playground for experimenting with firebase. Even though Firebase implementation in the Project itself works fine and i can import my Firebase it won't work on a Playground any more. Does somebody know how to add a working setup