why does the for loop in Swift Playground iterates over each element in a random order? I thought for loops iterate from the first element going to the last?
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
94 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
I have the simplest Playground to display image. I have images inside Resources. Somewhat it does not work and I am really confused. I am using macOS XCode.
I think on iPad Swift Playground this might work.
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
Image("image1")
.resizable()
.frame(width: 512, height: 512)
}
}
let hostingController = UIHostingController(rootView: ContentView())
PlaygroundPage.current.liveView = hostingController
Im new to Xcode getting this error in this playground, can someone help me here... This was In a playground btw
Thanks,
struct Digit {
var number : Int
init(_ n: Int){
self.number = n
}
mutating func changeNumberTo(_ n:Int) {
self.number = n
}
func otherFunction(_ f: ()->()) {
}
mutating func callAnotherFunction() {
otherFunction {
self.changeNumberTo(345) // *
}
}
}
var d = Digit(123) // Digit is a struct
print(d.number) //123
var d2 = d //Assignment!
d2.number = 42
print(d.number)
enum Node {
case none(Int)
indirect case left(Int, Node)
indirect case right(Int, Node)
indirect case both(Int, Node, Node)
}
I am typing string text on textDocumentProxy in a custom keyboard app. The input text includes newlines and punctuation letters, but when I try to edit the textDocumentProxy field, the textDocumentProxy.documentContextBeforeInput in case a newline \n is included, it does not return full content before input.
I placed the cursor on after the good morning word center, I got only good string text. The remaining "hi folks", words do not return.
Here are some examples I have tried.
var inputText = "Hi folks,
Good morning to everyone "
var txtBeforeCursor = textDocumentProxy.documentContextBeforeInput ?? ""
print("Before Cursor text : ",txtBeforeCursor)
Output is:
Before Cursor text : Good
I've decided I want my app, which has been shipped to the App Store, to support CloudKit, but it's a .swiftpm app (so I could work on it on the go on an iPad and Swift Playgrounds).
I've taken a half-hearted stab at it (there's more pressing stuff to work on and this is a nice to have for the moment), but is there a way to set up a new workspace in Xcode where I have two targets: a .swiftpm version of the app and a .xcodeproj app so I can enable CloudKit for my app and also ship it to the App Store with the same identifier?
Is there a way to make a .swiftpm app only available on the iPad?
I can see where I would restrict it in the autogenerated Package.swift, but there's nowhere in the Swift Playgrounds or Xcode 14 interface that I can find that will let me restrict it to iPad only.
It's causing my app to get rejected by the App Store team, as the iPhone version is too crowded... but it's designed for iPad... I just need to be able to specify that somewhere...
I have to admit that this is strange for me. Though I have been using playgrounds for years, but I only write small pieces of code to test simple ideas, and I never used another source file.
Today I want to add a new struct in Sources folder. To my surprise, I am not able to reference the struct in the main playground file.
Sources/testlets.swift:
struct Dummy {
var name: String
}
MyPlayground:
var box = Dummy(name: "abc")
// error: /.../MyPlayground.playground:22:11 Cannot find 'Dummy' in scope
Was doing the tutorials from Swift Playgrounds new lesson "Keep going with Apps" and on the "Bindings" chapter was asked to put a ColorPicker view.
To see the color options I should run the app instead of seeing it in the preview. I tried to do that but I don't get a response from Playgrounds...
Has someone had the same problem while doing this lesson?
Hi,
is there any possibility to localize my Swift Playgrounds APP?
In the Build meta data it is always only English, and the "traditional" localization process doesn't work in Swift Playgrounds on iPad or in Xcode on Mac.
I'm not able to see any live preview in playgrounds in the "Boogie Bot" file on page 2.
Can anyone help as to how I'll be able to make it work?
I'm practicing a swift 5 class, and have this issue:
Could not launch “I AM RICH”
Domain: IDEDebugSessionErrorDomain
Code: 3
Failure Reason: The operation couldn’t be completed. Unable to launch com.superdie.I-AM-RICH because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user.
User Info: {
DVTRadarComponentKey = 855031;
RawLLDBErrorMessage = "The operation couldn\U2019t be completed. Unable to launch com.superdie.I-AM-RICH because it has an invalid code signature, inadequate entitlements or its profile has not been explicitly trusted by the user.";
}
I'm not sure what can I do, some help would be nice :)
Hello, i am working on my project for the Swift Student Challenge and it came to my attention that the project must be built using Swift Playgrounds. I have run into an issue where I want to add multiple views to my project but it seems i am unable. How am i supposed to do this?
When I import a package in Swift Playgrounds on my iPad, I receive the following error:
This package interactions with libgit2, and it don’t have any release in the origin repository, so I find a existing fork which have release.
Playgrounds version: 4.3.1(1727.53)
Is it means that I install a software that supports unzip on iPad?
I want to make it like this
How to disable the button that open the side bar, I only need the content and the detail view. I don't need the sidebar view.
Below is my code
import SwiftUI
@available(iOS 16.0, *)
struct Screen: View {
@ObservedObject var userData = UserData()
@State private var isIntroShown = true
@State var Itema: Bool = false
@State private var showFoodDetail = false
@State var rb: Bool = false
@State var Setting: Bool = false
@State var Recipe: Bool = false
@Environment(\.defaultMinListRowHeight) var minRowHeight
@Environment(\.colorScheme) var colorScheme
@State private var searchText = ""
private let adaptiveColumns = [
GridItem(.adaptive(minimum: 170))
]
var columns = Array(repeating: GridItem(.flexible(), spacing: 10), count: 2)
var filteredRooms: [Room] {
if searchText.isEmpty {
return userData.rooms
} else {
return userData.rooms.filter { room in
let foodNames = room.food.map { $0.name.lowercased() }
return room.name.lowercased().contains(searchText.lowercased()) ||
foodNames.contains { $0.contains(searchText.lowercased()) }
}
}
}
@State private var columnVisibility = NavigationSplitViewVisibility.doubleColumn
var body: some View {
NavigationSplitView (columnVisibility: $columnVisibility){
} content: {
ScrollView{
GridView()
.padding(.horizontal)
.padding(.bottom, 20)
}.toolbar {
ToolbarItem(placement: .bottomBar){
Button(action:{self.Itema = true}) {
HStack {
Image(systemName: "plus.circle.fill").resizable().frame(width: 20, height: 20).foregroundColor(.white)
Text("New Item").foregroundColor(.white).bold()
}
}
.sheet(isPresented: self.$Itema){
NewItem(userData: self.userData)
}
}
ToolbarItem(placement: .bottomBar){
Button(action:{self.rb = true}) {
HStack {
Text("New Room").foregroundColor(.white)
}
}
.sheet(isPresented: self.$rb){
NewRoom(userData: self.userData)
}
}
ToolbarItem(placement: .navigationBarTrailing){
Button(action:{self.Setting = true}) {
HStack {
Image(systemName: "gear").foregroundColor(.white)
}
}
.sheet(isPresented: self.$Setting){
NavigationView {
NewItem( userData: userData)
.navigationBarItems(trailing:Button(action: {
self.Setting = false
}){
Text("Done")
}
)
}
}
}
}
.background(Color(red: 203/255, green: 237/255, blue: 207/255))
} detail: {
ZStack {
Text("")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(red: 220/255, green: 247/255, blue: 234/255))
}
.searchable(text: $searchText)
}
}