Try to learn some Swift coding but Playgrounds keeps crashing.
I run Playgrounds 4.1 on latest Monterey 12.7.5, from a MacBook Air dated back 2017.
Part of the error log says:
Thread 9 Crashed:: Dispatch queue: com.apple.UIKit._UIViewServiceInterfaceConnectionRequest com.apple.PlaygroundsMac.ExecutionExtension
The error can be reproduced by re-running the code; Everything goes well when the code was run at first time, but is doomed to fail at second run.
Any help?
Swift Playgrounds
RSS for tagLearn and explore coding in Swift through interactive learning experiences on the Swift Playgrounds app for iPadOS and macOS.
Posts under Swift Playgrounds tag
83 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
My Mac is older one. I just started to learn Swift. I want to practice it. So I downloaded Xcode 14.2 for MacOS 12.7.4 (21H1123)
On tutorials, it is showing live result. But for me nothing is happening. It is blank.
How do I enable it?
I've noticed Playgrounds crashing a lot lately, both on iPad and Mac. I have many Macs, Intel & M1, and 2 iPads, 7th Gen and 10.5" Pro. It's noticeably sluggish at the best of times progressively getting worse the last few updates, but worse than that it is hard crashing, losing data in the process. Anyone else seeing this? Not the end of the world, I'm a dev and use Xcode for anything substantial but I like to use Playgrounds on the iPad sometimes when I want to pop a quick idea down. I also plan to start creating playgrounds to help kids get into programming, so hoping this useful app isn't being neglected.
In Swift-UI Playgrounds Learn to Code 2 under the Chapter "Variables" and the exercise "Checking for Equal Values", there is no instruction to use the predefined variable numberOfSwitches in the goal instruction.
I am trying to include custom symbol resources in a swift package for use in other projects. I have read the documentation here:
https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package
However there is no example code and I have created a very simple project to try and get this working but it does not.
.target(
name: "TestLibrary",
resources: [.process("Resources/Media.xcassets")]
),
This is in the Package.swift file and the path relative to the Package.swift file is Sources/TestLibrary/Resources/Media.xcassets.
There's a GitHub project with an example custom SF Symbol SVG (but this may not be available in the future): https://github.com/kudit/TestLibrary
Including this as a package in a blank Swift Playgrounds App project and just importing the TestLibrary and including TestImageView() in the ContentView technically works (it shows the system full star image, but none of the ways of rendering the test symbol as recommended works. It does work for a few of the options in the #Preview when viewing the project in Xcode.
Anyone have any suggestions or know how to get the resources to be accessible from outside the module? I have tried both the .copy( option as well as the .process( option and neither seem to work.
Does anyone know of any documentation for the various directives in the guidebook?
Things like @GuideBook, @Guide, @Task, @SuccessMessage, etc.
Thanks,
David
Hello All,
I happen to remove "Playgrounds" folder from my iCloud drive, and afterwards Playground is no longer functioning but repeatedly crashes.
It was okey before deletion, but now any operation to create or download playground then Playground App crashes all the time.
Issue not resolved even creating same name folder by manual,
Issue not resolved even re-install Playground - folder in iCloud will not created.
I guess I need to fully uninstall PlayGround completely, then start from scratch to let Playground App to hold init step to generate required folder in iCloud, but not sure how to do it.
Please give kind help if anyone knows about this issue, or if anyone knows complete deletion step of Playground.
Best wishes, tons of thanks in advance.
Best Regards,
Issey Hamada
I'm getting the following error when previewing my Swift Playground package:
Unrecognized platform name 'xrOS'; did you mean 'iOS'?
Anyone know how to silence this? I don't have xrOS anywhere in my code so I'm guessing this is something with Swift Playgrounds or with the compiler.
I was expecting all of the code to run in main thread, but both task and async function is working in backfround thread. Any explanations?
I tried to use navigationstack, and it works. but couldn't print the path, and with the message: " NavigationPath(_items: SwiftUI.NavigationPath.(unknown context at $7ff84b690a28).Representation.eager([SwiftUI.(unknown context at $7ff84b6907f0).CodableItemBox<Swift.String>]), subsequentItems: [], iterationIndex: 0). "
`import SwiftUI
var toDos: [String] = [ "list1", "list2", "list3" ]
struct ContentView: View { @State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
List {
ForEach(toDos, id:\.self) { toDo in
Button(action: {
path.append(toDo)
print(path)
}, label: {
Text("go to " + toDo)
})
}
}
.navigationDestination(for: String.self) { toDo in
Text("page for " + toDo)
}
}
}
}
#Preview { ContentView() }`
I tried navigationlink and simulator still works fine, but cannot print anything of path
Whenever we submit a new release to the App Store we get a nag email from Apple that states, "The app binary listed below was 199.2 MB when you submitted it, but will be 223.9 MB once processed for the App Store. This exceeds the cellular network download size limit and may require your app to be downloaded over Wi-Fi."
However, when I download the app from the App Store and have the Settings set to "Alway Ask" on my phone the alert shows 129 MB, which is matches up closely with what we see in the TestFlight metadata for all device types except "Universal".
What is "Universal" device type in these days of thinning? And why is Apple apparently using that number to generate the nag email?
I have made a swift playground with the .playground extension but the WWDC24 Swift Student Challenge says I have to submit a .swiftpm file. What do I do to convert it to .swiftpm?
I want to get the loop times info in playground. But it seems to only display the latest result for a loop on the right side. Do I miss anything? Xcode 15.0.1
import Cocoa
for i in 1...5{
print("\(i)")
}
I have a screenshot:
How do I add a already made CoreML model into my playground? I tried what people recommended online -- building a test project and get the .mlmodelc file and put that in the playground along with the autogenerated class for the model. However, I keep on getting so many errors.
The errors:
Unexpected duplicate tasks
Target 'help' (project 'help') has write command with output /Users/cpulipaka/Library/Developer/Xcode/DerivedData/help-appuguzbduqvojfwkaxtnqkozecv/Build/Intermediates.noindex/Previews/help/Intermediates.noindex/help.build/Debug-iphonesimulator/help.build/adc7818afdf4ae03fd98cdd618954541.sb
Target 'help' (project 'help') has write command with output /Users/cpulipaka/Library/Developer/Xcode/DerivedData/help-appuguzbduqvojfwkaxtnqkozecv/Build/Intermediates.noindex/Previews/help/Intermediates.noindex/help.build/Debug-iphonesimulator/help.build/adc7818afdf4ae03fd98cdd618954541.sb
Unexpected duplicate tasks
Showing Recent Issues
Target 'help' (project 'help'): CoreMLModelCompile /Users/cpulipaka/Library/Developer/Xcode/DerivedData/help-appuguzbduqvojfwkaxtnqkozecv/Build/Intermediates.noindex/Previews/help/Products/Debug-iphonesimulator/help.app/ /Users/cpulipaka/Desktop/help.swiftpm/Resources/ZooClassifier.mlmodel
Target 'help' (project 'help'): CoreMLModelCompile /Users/cpulipaka/Library/Developer/Xcode/DerivedData/help-appuguzbduqvojfwkaxtnqkozecv/Build/Intermediates.noindex/Previews/help/Products/Debug-iphonesimulator/help.app/ /Users/cpulipaka/Desktop/help.swiftpm/Resources/ZooClassifier.mlmodel
ZooClassifier.mlmodel: No predominant language detected. Set COREML_CODEGEN_LANGUAGE to preferred language.
Hi,
I am trying to create a variable of type Color inside the swift data model in Xcode playground .
This gives me these errors :
No exact matches in call to instance method 'setValue'
No exact matches in call to instance method 'getValue'
No exact matches in call to instance method 'setValue'
What is the problem?
I have a CollectionView in my SwiftUI App. The collectionView is wrapped in a UIViewRepresentable. If I tap on a collectionView cell normally the function isn't called but if I hold the cell down the console prints <0x107507790> Gesture: System gesture gate timed out. and when I let go of the cell after that's printed then didSelectItem is called.
Here is my CollectionView Class:
class SessionsCollectionView: UIView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 30
let collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.dataSource = self
collectionView.delegate = self
collectionView.clipsToBounds = false
collectionView.delaysContentTouches = false
collectionView.register(SessionCell.self, forCellWithReuseIdentifier: "cell")
collectionView.register(SessionsHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header")
return collectionView
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = .clear
setupCollectionView()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setupCollectionView() {
addSubview(collectionView)
collectionView.backgroundColor = .clear
collectionView.alwaysBounceVertical = true
collectionView.alwaysBounceHorizontal = false
collectionView.delaysContentTouches = false
collectionView.contentInset = .init(top: 20, left: 0, bottom: 20, right: 0)
collectionView.showsVerticalScrollIndicator = false
NSLayoutConstraint.activate([
collectionView.topAnchor.constraint(equalTo: topAnchor),
collectionView.leadingAnchor.constraint(equalTo: leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: trailingAnchor),
collectionView.bottomAnchor.constraint(equalTo: bottomAnchor)
])
}
// MARK: Header
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionView.elementKindSectionHeader {
let sectionHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "header", for: indexPath) as! Header
return sectionHeader
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
let width: CGFloat = collectionView.frame.width
let height: CGFloat = 33 + 20
return CGSize(width: width, height: height)
}
// MARK: - UICollectionViewDataSource
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! SessionCell
return cell
}
// MARK: - UICollectionViewDelegateFlowLayout
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = collectionView.bounds.width
let height = 150
return CGSize(width: collectionView.bounds.width, height: height)
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print(indexPath.row)
}
}
struct SessionsCollectionViewWrapper: UIViewRepresentable {
var sessionViewNavigation: SessionViewNavigation
func makeUIView(context: Context) -> SessionsCollectionView {
let sessionsCollectionView = SessionsCollectionView()
return sessionsCollectionView
}
func updateUIView(_ uiView: SessionsCollectionView, context: Context) {
// Update any properties or handle updates if needed
}
}
Hello,
For the Swift Student Challenge, do I need to worry about submitting a clean source code with comments? Or does Apple judge submissions solely based on their user experience with the app?
Thanks!
Im making an app that uses drag&drop but, it doesn't work.
This is made with Swift Playground.
If you can find a solution, please let me know.
Here is the code.
//MARK: Drop Area
@ViewBuilder
func DropAera()->some View{
VStack(spacing: 12){
ForEach($rows,id:\.self){$row in
HStack(spacing: 10){
ForEach($row){$item in
Text(item.value)
.font(.system(size: item.fontSize))
.padding(.vertical,5)
.padding(.horizontal,item.padding)
.opacity(item.isShowing ? 1 : 0)
.background{
RoundedRectangle(cornerRadius: 6, style: .continuous)
.fill(item.isShowing ? .clear : .gray.opacity(0.25))
}
.background{
// If Item is Dropped into Correct Plase
RoundedRectangle(cornerRadius: 6, style: .continuous)
.stroke(.gray)
.opacity(item.isShowing ? 1 : 0)
}
// MARK: Adding Drop Operation
// MARK: Adding Drag Drop Operation
.onDrop(of: [.url], isTargeted: .constant(false)) {
providers in
if let first = providers.first{
let _ = first.loadObject(ofClass: URL.self) {
value,error in
guard let url = value else{return}
if item.id == "\(url)"{
droppedCount += 1
let progress = (droppedCount / CGFloat(characters.count))
withAnimation{
item.isShowing = true
updateShuffledArray(character: item)
self.progress = progress
}
}
else{
//Animating When Wrong text
animateView()
}
}
}
return false
}
}
}
if rows.last != row{
Divider()
}
}
}
}
@ViewBuilder
func DragArea()->some View{
VStack(spacing: 12){
ForEach(shuffledRows,id: \.self){row in
HStack(spacing: 10){
ForEach(row){item in
Text(item.value)
.font(.system(size: item.fontSize))
.padding(.vertical,5)
.padding(.horizontal,item.padding)
.background{
RoundedRectangle(cornerRadius: 6, style: .continuous)
.stroke(.gray)
}
// MARK: Adding Drag Drop Operation
.onDrag{
// Returning ID to find whitch Item is Moving
return .init(contentsOf: URL(string: item.id))!
}
.opacity(item.isShowing ? 0 : 1)
.background{
RoundedRectangle(cornerRadius: 6, style: .continuous)
.fill(item.isShowing ? .gray.opacity(0.25) : .clear)
}
}
}
if shuffledRows.last != row{
Divider()
}
}
}
}
Can anyone tell me how to use Swift Data and Core Data with playground?
Hello,
Does anyone know how to restrict my app playground to run on iPhones only (not even iPads) and to always be presented in portrait mode? I'm using Xcode.
Thanks for any help!