Posts

Post marked as solved
1 Replies
You can re-write it like this:     let result = randomIV.withUnsafeMutableBytes {(bufPointer: UnsafeMutableRawBufferPointer) in         SecRandomCopyBytes(kSecRandomDefault, bufPointer.count, bufPointer.baseAddress!)     } Or a little more simply:     let result = randomIV.withUnsafeMutableBytes {         SecRandomCopyBytes(kSecRandomDefault, $0.count, $0.baseAddress!)     }
Post not yet marked as solved
1 Replies
It seems the documentation is quite unclear, but you may need to import QuickLook to use the modifier quickLookPreview(_:).
Post not yet marked as solved
1 Replies
You should do it in a content view controller of the UINavigationController. SecondViewController.swift import UIKit class SecondViewController: UINavigationController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemBackground self.viewControllers = [RootViewController()] } } RootViewController.swift import UIKit class RootViewController: UIViewController { override func viewDidLoad() { title = "Decount timers" super.viewDidLoad() view.backgroundColor = .systemBackground navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(didTapAddButton)) } @objc func didTapAddButton(_ sender: Any) { //... } }
Post not yet marked as solved
1 Replies
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.
Post not yet marked as solved
2 Replies
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.
Post not yet marked as solved
1 Replies
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.
Post not yet marked as solved
2 Replies
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.)
Post marked as solved
1 Replies
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.
Post marked as solved
1 Replies
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() } } }
Post not yet marked as solved
3 Replies
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.
Post marked as solved
4 Replies
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.
Post marked as solved
2 Replies
I would write it like this: let p_vertexData = vertexData.withUnsafeBufferPointer {bufPtr in Data(buffer: bufPtr) }
Post not yet marked as solved
1 Replies
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.
Post not yet marked as solved
2 Replies
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.
Post not yet marked as solved
7 Replies
Is it possible to add iPhone simulator there? As far as I know, the answer is NO. Swift Playgrounds 4 does not have a tool to explicitly test how your app looks like in each size of devices, nor it does not have an ability to run the app on actual iPhones.