Post not yet marked as solved
The following code does not work in an Xcode Playgrounds or the Swift Playgrounds App on iOS oder macOS.
But the same code works when used in an app.
Does anyone know how to get the notifications running in a Playground?
import GameController
import Combine
import SwiftUI
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
var cancellables = Set<AnyCancellable>()
NotificationCenter.default.publisher(for: NSNotification.Name.GCControllerDidConnect)
.subscribe(on:DispatchQueue.global())
.print()
.receive(on: DispatchQueue.main)
.sink { notification in
print(notification)
}.store(in: &cancellables)
let disConnect = NotificationCenter.default.publisher(for: NSNotification.Name.GCControllerDidDisconnect)
.print()
.subscribe(on:DispatchQueue.global())
.receive(on: DispatchQueue.main)
.sink { value in
print(value)
}.store(in: &cancellables)
XCode 12.5.1
The playground can't review anything in the right or the bottom when I try to run something like print("Hello World!")
I try to creat a new playground or open the Offical GuidedTour, but it's still not work.
I don't know how to fix that
Post not yet marked as solved
Hi!
I'm fairly new to Swift and was trying to mess around with it in Xcode and Playgrounds. The thing is that it refuses to print anything to the console. I have it on "automatic run" (signified by the purple play button) but have also tried it in "manual run". Does anyone have an idea about what is going on?
Post not yet marked as solved
Is there a way to make this code correctly function, loading a webpage (works using iPad playgrounds, not MacOS playground)?
import SafariServices
import Foundation
import PlaygroundSupport
import UIKit
import WebKit
scene.clear()
scene.backgroundImage = imageLiteral(resourceName: "add own foto")
let points = scene.circlePoints(radius: 200, count: 100)
var pointIndex = 0
func doSomething(touch: Touch) {
if touch.previousPlaceDistance < 60 { return }
let EmojiIndex = "🤱👨👩👦👨👩👧👦🚆🚙🚴♂️🏊♂️🏌️♂️📱🧸🌳🍏👨🏻🦳👵🏻".componentsByCharacter()
let Karakters = Graphic(text: EmojiIndex.randomItem)
scene.place(Karakters, at: touch.position)
Karakters.scale = 0.5
if pointIndex >= points.count {
pointIndex = 0
}
pointIndex += 1
let position = points[pointIndex % points.count]
Karakters.move(to: position, duration: 1.0)
}
let tool1 = Tool(name: "Tool 1", emojiIcon: "1️⃣")
tool1.onTouchMoved = doSomething(touch:)
scene.tools.append(tool1)
func buttonPressed () {
let test = SFSafariViewController(url: URL(string:"enter_url")!)
test.title = "Open webpage"
PlaygroundPage.current.liveView = UINavigationController(rootViewController: test)
}
}
let button = Button(name: "Open website")
button.onPress = buttonPressed
scene.button = button
Kind regards, David
I'm using playground to experiment with Combine. I found this example on a blog. I expect it to create the Future publisher, wait a couple seconds then send the promise and complete.
import Foundation
import Combine
import SwiftUI
let future = Future<Int, Never> { promise in
print("Creating")
DispatchQueue.global().asyncAfter(deadline: .now() + 2) {
print("sending promise")
promise(.success(1))
}
}
future
.sink(receiveCompletion: { print("receiveCompletion:\($0)") },
receiveValue: { print("receiveValue:\($0)") })
print("end")
The output I expect:
Creating
end
sending promise
receiveValue: ...
receiveCompletion: ...
The output I get:
Creating
end
sending promise
I don't see an indication the promise was executed. What am I doing wrong?
Post not yet marked as solved
I am writing code in swift playgrounds iPad, and multiple things say "Cannot find '***' in scope". What do I need to import into swift playgrounds? Do I need to do import SwiftUI. I'm not to sure.
Post not yet marked as solved
I am trying to use the playground to test some simple code. However, I cannot get it to work. Even the most simple hello world does not work. The build status at the top says build succeeded but there is no output to either the console or the live view. Here is the code I have been testing with:
import UIKit
var greeting = "Hello, playground"
print(greeting)
Post marked as Apple Recommended
Hi,
Is the date Format "dd.mm.yyyy" available?
Post not yet marked as solved
when i add these 2 multi - dimensional array
i am not getting sum of the array
rather it is concatenation process
so guys can you help me out
Post not yet marked as solved
In WWDC21, we saw the possibility to build and distribute SwiftUI apps on iPad.
I wonder how to find it?
Post not yet marked as solved
Hi,
The code below from the demo works on the MAC but not on the iPad, it Aborts on the Circle() line, if I remove the newly added Text command the code run's again.
What am I doing wrong?
import SwiftUI
import PlaygroundSupport
struct ProgressView: View {
var body: some View {
ZStack {
Circle()
.stroke(lineWidth: 40)
.foregroundColor(.blue)
Text("25%")
}
}
}
PlaygroundPage.current.setLiveView(ProgressView()
.padding(150))
Post not yet marked as solved
Hello 👋,
I recently started running the new macOS beta [macOS Monterey] everything, all my apps, work great however I did notice since I updated that the functionality to see my Results Bar and Debug area on Xcode have disappeared.
To confirm this I created a new blank playground on Xcode, and I tried resseting my workspace. However, no code is showing on the results bar, very strange.
Could someone help me out figure out what is going? Could this be an issue on my part or there are more users with a similar problem?
Thanks
Post not yet marked as solved
I would like to know how to be able to get it so when you press a button, it will up the contrast by 5, and so on. This is for Swift Playgrounds iPad.
Post not yet marked as solved
hello,
it's my first day with swift and my first-day programming in general and I'm already facing a problem...
I don't understand why when I try to execute the "script" by clicking on the arrow on line 1 or on the " play" button at the bottom, the script is not shown to me either in the right column or at the bottom...
Could someone kindly help me
Post not yet marked as solved
Hello! I am fairly new to Swift, and I am trying out random things inside of Swift. I also tried learning with Swift Playgrounds, but it feels like code.org only that you type in functions. If you know the best learning methods, please let me know! Thanks, WE
P.S. I know Roblox LuaU, so Swift is not my first language.
I want to make a truth or dare game in swift playground for iPad but I can't make a button that
prints more than one dare or truth. I tried to make a var that have all dares and then i put it in the
(class Responser NSObject )the var looks like this( var dares = ["dare1", "dare 2" ...]) but it is
giving me error that says (cannot assign value of type '[String]'to type 'String') and the 2nd
thing I tried was (let dares = ["dare 1", "dare 2"…]) that gave me the same error.
my code looks like this
import PlaygroundSupport
import UIKit
let View = UIView()
View.backgroundColor = .blue
let lbl = UILabel(frame: CGRect(x: 210, y: 329, width: 200, height: 50))
lbl.text = "hi!"
View.addSubview(lbl)
lbl.textColor = .white
let button = UIButton(frame: CGRect(x: 67, y: 500, width: 100, height: 50))
button.backgroundColor = .green
//button.setTitleColor(#colorLiteral(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0), for: UIControlState.selected)
button.setTitle("button", for: UIControl.State.selected)
button.layer.cornerRadius = 10
View.addSubview(button)
let button1 = UIButton(frame: CGRect(x: 300, y: 500, width: 100, height: 50))
button1.backgroundColor = .red
//button1.setTitleColor(#colorLiteral(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0), for: UIControlState.selected)
button1.setTitle("button1", for: UIControl.State.selected)
button1.layer.cornerRadius = 10
View.addSubview(button1)
class Responser: NSObject
{
//Method to be called
@objc func printname()
{
lbl.text = "1"
}
}
let responder = Responser()
button.addTarget(responder, action: #selector(Responser.printname), for:.touchUpInside)
class Responser1: NSObject
{
//Method to be called
@objc func printname()
{
lbl.text = "2"
}
}
let responder1 = Responser1()
button1.addTarget(responder1, action: #selector(Responser1.printname), for:.touchUpInside)
PlaygroundPage.current.liveView = View
Post not yet marked as solved
I Have installed swift playground on my ipad..
but i saw Many different between the show for swift playground on the event wwdc21..
Here:
https://youtu.be/3ELYyOwJCpM |..
Where this radical difference is clear..and my second question is if there is a difference between swift playground and xcode playground?
Post not yet marked as solved
Hi, you say swift playground 5 will come to ipad when the ipados 15 come out, yesterday the Ipados 15 came out i update my ipad but swift playground 5 update didn’t came out with Ipados 15.
so i want to know when the swift playground 5 came out and how can i update it
I have updated to iPadOS 15 but I still have the old interface. However I would like the new interface announced at WWDC21. Is this possible yet?
Post not yet marked as solved
When i use on my swiftUI
app the (@Binding)
Some error coming:
Error:
Property wrappers are not yet supported on local properties
And:
Closure containing a declaration cannot be used with function builder 'ViewBuilder'
Any body Help me?