Post

Replies

Boosts

Views

Activity

Reply to Use placeholder app icon in view in Swift Playgrounds 4
I'm not sure how iOS handles that, but it seems the iOS App Icon resource with name AppIcon in Assets.xcassets is handled specially by iOS and you cannot access it from inside your app. If you want to use it as Image("..."), you may need to create an Image Set resource with another name than AppIcon, and copy the same image into it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Add a ProgressView during a simple URLSession POST request in SwiftUI
In your code, requestTest is a name of a function. Using a function name in a condition of if-statement does not make sense. To use if-statement, you need an expression returning Bool. Please try something like this: import SwiftUI struct ContentView: View { @State private var tweetID = "" @State private var tweetStatus = "" @State private var response = "" @State var showAlert = false @State var sendToWebhook = false @State var isRequestInProgress: Bool = false //<- var body: some View { NavigationView { Form { Section(footer: Text("Test")) { TextField("Field to place response data", text: $response) TextEditor( text: $tweetStatus) .frame(height: 100) } Section { Button("Get Data") { // Where progress should start before function //↓Writing a View in an action closure does not make sensse //ProgressView("Test", value: 100, total: 100) requestTest() { results in response = results if response == "No Data!" { showAlert = true } } } if isRequestInProgress { //<- ProgressView() } } } .alert(isPresented: $showAlert) { Alert(title: Text("Tweet Sent"), message: Text("Your Tweet is sent! Your Tweet ID is shown in the field"), dismissButton: .default(Text("OK"))) } } } func requestTest(completion: @escaping(String) -> ()) { if let url = URL(string: "https://requestbin.net/r/ag4ipg7n") { var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") var components = URLComponents(url: url, resolvingAgainstBaseURL: false)! components.queryItems = [ URLQueryItem(name: "TweetID", value: response), URLQueryItem(name: "Status", value: tweetStatus)] if let query = components.url!.query { request.httpBody = Data(query.utf8) } self.isRequestInProgress = true //<- let task = URLSession.shared.dataTask(with: request) { data, response, error in //↓ defer { DispatchQueue.main.async { self.isRequestInProgress = false } } if let data = data, let apiResponse = String(data: data, encoding: .utf8) { // IF Completed, these actions are shown below completion(apiResponse) self.showAlert = true tweetStatus = "" } else { completion("No Data!") } } task.resume() } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to Failed to produce diagnostic for expression in SwiftUI, XCode 13.2
You should better include clear sentences explaining what you want to ask here. Have you come here to just report your bug? Or want to find a solution to fix the bug? Anyway, your code lacks one pair of parentheses at about 32nd line: VStack(alignment: .center, spacing: 10) { Text("Computers Choice: \(options[computersChoice].name)") .fontWeight(.bold) .padding //<- Image("\(options[computersChoice].name)") .resizable() .frame(width: 100, height: 100) .padding() Text("You need to \(winOrLose ? "Win" : "Lose")") .fontWeight(.bold) } So, you need to fill parentheses there: VStack(alignment: .center, spacing: 10) { Text("Computers Choice: \(options[computersChoice].name)") .fontWeight(.bold) .padding() //<- Image("\(options[computersChoice].name)") .resizable() .frame(width: 100, height: 100) .padding() Text("You need to \(winOrLose ? "Win" : "Lose")") .fontWeight(.bold) } Usual compilers can detect where this sort of simple syntax error is occurring, you can send a bug report to swift.org as suggested.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’22
Reply to What is dynamic shared object (DSO) handle that #dsohandle applies to in Swift?
Searching with swift dsohandle, I can find a few discussions. https://twitter.com/chriseidhof/status/722352741767639040?lang=en https://github.com/apple/swift-log/issues/72 https://youtrack.jetbrains.com/issue/OC-14546 Estimating from the descriptions, dynamic shared object seems to be representing the dynamically linked libraries such as .dylib or .so currently running. It may be useful for the authors of libraries using dynamically linked libraries, where they can add a little more info for logging inside the libraries, but not so useful for usual developers just using the libraries.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’22
Reply to My app only displays back button
Hard to say something sure with just watching the screen shot. Can you show the code of your app including the root view?
Replies
Boosts
Views
Activity
Jan ’22
Reply to Expired Developer Account
I'd like to build/sign/test an app on my own devices You can build and test your apps on your devices if you have an Apple ID used as Developer account, paid or not. The restriction is a bit stronger than paid membership, but it may not be a big issue when you just want to use your own device.
Replies
Boosts
Views
Activity
Jan ’22
Reply to IOS Swift Playgrounds on iPad - enable Background modes
Is there any way to do this without Xcode or will I need a newer Mac? As far as I tried till now, Swift Playgrounds 4 does not have an ability to make an app with Background Modes enabled. You may need to get a newer Mac capable of running the latest Xcode, or else you may need to re-consider the functionalities of your app.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Why aren't the Metal Feature Set Tables up to date?
Better send a bug report than asking why. Have you already sent one?
Topic: Graphics & Games SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to How to get data from [Float] correctly?
I would write it like this: let p_vertexData = vertexData.withUnsafeBufferPointer {bufPtr in Data(buffer: bufPtr) }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Creating A Card View Tutorial Theme Issue
Is there something I'm missing? The code you have shown looks correct. One possibility, have you started your project with StartingProject? (Included in the Project download link.) You need Assets.xcassets to make the code work.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Use placeholder app icon in view in Swift Playgrounds 4
I'm not sure how iOS handles that, but it seems the iOS App Icon resource with name AppIcon in Assets.xcassets is handled specially by iOS and you cannot access it from inside your app. If you want to use it as Image("..."), you may need to create an Image Set resource with another name than AppIcon, and copy the same image into it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Add a ProgressView during a simple URLSession POST request in SwiftUI
In your code, requestTest is a name of a function. Using a function name in a condition of if-statement does not make sense. To use if-statement, you need an expression returning Bool. Please try something like this: import SwiftUI struct ContentView: View { @State private var tweetID = "" @State private var tweetStatus = "" @State private var response = "" @State var showAlert = false @State var sendToWebhook = false @State var isRequestInProgress: Bool = false //<- var body: some View { NavigationView { Form { Section(footer: Text("Test")) { TextField("Field to place response data", text: $response) TextEditor( text: $tweetStatus) .frame(height: 100) } Section { Button("Get Data") { // Where progress should start before function //↓Writing a View in an action closure does not make sensse //ProgressView("Test", value: 100, total: 100) requestTest() { results in response = results if response == "No Data!" { showAlert = true } } } if isRequestInProgress { //<- ProgressView() } } } .alert(isPresented: $showAlert) { Alert(title: Text("Tweet Sent"), message: Text("Your Tweet is sent! Your Tweet ID is shown in the field"), dismissButton: .default(Text("OK"))) } } } func requestTest(completion: @escaping(String) -> ()) { if let url = URL(string: "https://requestbin.net/r/ag4ipg7n") { var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type") var components = URLComponents(url: url, resolvingAgainstBaseURL: false)! components.queryItems = [ URLQueryItem(name: "TweetID", value: response), URLQueryItem(name: "Status", value: tweetStatus)] if let query = components.url!.query { request.httpBody = Data(query.utf8) } self.isRequestInProgress = true //<- let task = URLSession.shared.dataTask(with: request) { data, response, error in //↓ defer { DispatchQueue.main.async { self.isRequestInProgress = false } } if let data = data, let apiResponse = String(data: data, encoding: .utf8) { // IF Completed, these actions are shown below completion(apiResponse) self.showAlert = true tweetStatus = "" } else { completion("No Data!") } } task.resume() } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Failed to produce diagnostic for expression in SwiftUI, XCode 13.2
You should better include clear sentences explaining what you want to ask here. Have you come here to just report your bug? Or want to find a solution to fix the bug? Anyway, your code lacks one pair of parentheses at about 32nd line: VStack(alignment: .center, spacing: 10) { Text("Computers Choice: \(options[computersChoice].name)") .fontWeight(.bold) .padding //<- Image("\(options[computersChoice].name)") .resizable() .frame(width: 100, height: 100) .padding() Text("You need to \(winOrLose ? "Win" : "Lose")") .fontWeight(.bold) } So, you need to fill parentheses there: VStack(alignment: .center, spacing: 10) { Text("Computers Choice: \(options[computersChoice].name)") .fontWeight(.bold) .padding() //<- Image("\(options[computersChoice].name)") .resizable() .frame(width: 100, height: 100) .padding() Text("You need to \(winOrLose ? "Win" : "Lose")") .fontWeight(.bold) } Usual compilers can detect where this sort of simple syntax error is occurring, you can send a bug report to swift.org as suggested.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to How to get upload progress when using "await urlSession.upload()"
Something I need here maybe? Correct. Use self, if you implement urlSession(_:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:) in the same class. (Please do not forget to make the class conform to URLSessionTaskDelegate.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to What is dynamic shared object (DSO) handle that #dsohandle applies to in Swift?
Searching with swift dsohandle, I can find a few discussions. https://twitter.com/chriseidhof/status/722352741767639040?lang=en https://github.com/apple/swift-log/issues/72 https://youtrack.jetbrains.com/issue/OC-14546 Estimating from the descriptions, dynamic shared object seems to be representing the dynamically linked libraries such as .dylib or .so currently running. It may be useful for the authors of libraries using dynamically linked libraries, where they can add a little more info for logging inside the libraries, but not so useful for usual developers just using the libraries.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Mac Catalyst target does not build on M1 with this error: Could not read serialized diagnostics file: error("Invalid diagnostics signature")
As far as I experience till now, the error Could not read serialized diagnostics file is temporary. Please try Clean Build Folder, re-starting Xcode or re-starting your Mac and take sometime to see what happens next.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to I can't preview my project
Can you show your code? (Not partially, the whole code. And not image, code as text using Code Block.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jan ’22
Reply to Swift Playgrounds 4 - GeoJson
Can you show your code?
Replies
Boosts
Views
Activity
Jan ’22
Reply to About background playback on Swift Playgrounds4
Please check this thread. To create an app which can play music in background, you need to create an app with Background Modes enabled for Audio. As for now, you cannot make it within an app project of Swift Playgrounds 4. You may need to do it with Xcode on a Mac.
Replies
Boosts
Views
Activity
Jan ’22