Post

Replies

Boosts

Views

Activity

Reply to How can I press a button from one view and activate sth in another view?
Thanks for showing additional code. But please use the Code block feature shown as < > at the bottom bar of the editing area. (And please be more punctual about identifiers. Identifiers in Swift are case-sensitive and a slight difference may confuse readers.) if it is possible to use @binding properties with a Bool var  Of course you can. When you want to share a Bool var between views, you declare an @State var in the parent view and pass the Binding of it to the child view. Play.swift: struct Play: View { &#9;&#9;@State var graphIsOn: Bool = false &#9;&#9;@State var showsGraph: Bool = true &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;//... &#9;&#9;&#9;&#9;&#9;&#9;if showsGraph { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;ViewGraph(isOn: $graphIsOn)&#9;//Pass Binding to child view &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;//... &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;.toolbar { &#9;&#9;&#9;&#9;&#9;&#9;ToolbarItem(placement: .primaryAction) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Menu{ &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Section { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//WHEN I PRESS THIS BUTTON, I WANT THE GRAPH TO START &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;graphIsOn = true &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}, label: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Start recording") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;//WHEN I PRESS THIS BUTTON, I WANT THE GRAPH TO STOP &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;graphIsOn = false &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}, label: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Stop recording") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;label: { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Label("Add", systemImage: "playpause") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;} } ViewGraph.swift struct ViewGraph: View { &#9;&#9; &#9;&#9;//... &#9;&#9;//&#9;variables graph &#9;&#9; &#9;&#9;@Binding public var isOn: Bool //This is the var which starts the graph &#9;&#9; &#9;&#9;let sampleDataC: [CGFloat] = [0.1, 0.2, 0.45, 0.6, -0.8, -1.1, -0.4, 0.1, 0.2, 0.45, 0.6, -0.8, -0.2, 0.5, 0.3] &#9;&#9; &#9;&#9;@State private var colorConG = Color.white &#9;&#9; &#9;&#9;@State private var viewID = 0 &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;//... Use `isOn` as your `on`... &#9;&#9;} } (I renamed on to isOn, as on is too short to be meaningful.)
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Failed to produce diagnostic for expression; please file a bug report
When you ask something about errors, please specify the line the error occurs. I guess the error is shown on this line: var body: some View {. Unfortunately, the error Failed to produce diagnostic for expression is stating that Swift compiler found some errors somewhere but cannot report the right position and the right reason. This seems to be a severe flaw as a practical compiler and you should better send a bug report as suggested. You may need to comment out part by part and find which part of your code is causing errors. As far as I tried, if I comment out this part, the code compiles: &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: self.login(email: $email, password: $password)) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Log in") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.font(.headline) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(.white) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 371,height: 40) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(Color.yellow) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}.cornerRadius(4.0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} The part shown above has several errors: The action parameter of Button.init(action:label:) needs to be a closure You are passing the result of login(email:password:), which is declared as not returning values. It is not a closure. The parameters email and password needs to be String You are passing $email and $password, the type of $ prefixed names are Binding<String> here. Not String. You may need to fix two things as follows: &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Button(action: {self.login(email: email, password: password)}) {//<- &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text("Log in") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.font(.headline) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.foregroundColor(.white) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.frame(width: 371,height: 40) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.background(Color.yellow) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;}.cornerRadius(4.0) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;} (Please do not miss the enclosing braces passed to action, which creates a closure.) I needed to guess many parts as may underscores (_) are missing and I have never used Alamofire things in my apps. So, there may be more parts you need to fix. But I believe Swift compiler would generate better diagnostics once you fix the part shown above. Some other things: Please use Code block feature of this site. Shown with an icon like < >. In Swift, type names should start with Capital letter, loginPage and forgotPasswordPage should be LoginPage and ForgotPasswordPage. In Swift, you usually do not use snake-case identifiers like hidden_password, it should be hiddenPassword. Using NSPredicate is not a good way just for validating a String. You can use regex based comparison or NSRegularExpression.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
but how do I render the CIImage into some bitmap? There are many ways but the simplest way here is using createCGImage(_:from:)... Oh, you are already using it, but disposing the result. Change your generateQRCodeImage(url:) as follows: &#9;&#9;func generateQRCodeImage(url : String) -> UIImage { &#9;&#9;&#9;&#9;let data = Data(url.utf8) &#9;&#9;&#9;&#9;filter.setValue(data, forKey: "inputMessage") &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;if let qrCodeImage = filter.outputImage { &#9;&#9;&#9;&#9;&#9;&#9;if let cgImage = context.createCGImage(qrCodeImage, from: qrCodeImage.extent) { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return UIImage(cgImage: cgImage) &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;return UIImage(systemName: "xmark") ?? UIImage() &#9;&#9;} CGImage is the type to represent a bitmap based image.
Jan ’21
Reply to Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
Generally, EXC_BAD_INSTRUCTION is used by Swift runtime as an intentional crash. In the line specified, you use as!-casting, which is telling Swift compiler "Please crash my app when the type conversion is unable". The outputImage of CIFilter is a CIImage which cannot be converted to CGImage with as-casting. You can use UIImage(ciImage: qrCodeImage) instead of UIImage(cgImage: qrCodeImage as! CGImage), if you just need to avoid crashing here. But if you want to get some bitmap image from the UIImage later, you may need to render the CIImage into some bitmap.
Jan ’21
Reply to UIActivityViewController cannot save plist to local application's Documents
I have a single view controller, the app is simple. Thanks for showing additional info. But I tried in an app with a single view controller and UIActivityViewController worked as I described. So, that cannot be a good help to solve your issue. I can say nothing more, if no info more. There may be some readers who want to help if you could show enough info to help.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’21
Reply to Rss
I already have one, riddlewednesday.net/riddle is the page I want and I want to take the first block of text. Then you just need to solve just a few issues... How to update the site weekly (maybe this is already done?) How to make your app invoked to access the site weekly How to make your app download the content of the site How to make your app choose the first block of text from the content A few, but too many for a single thread. You should better choose one topic for this thread and start other threads when it is resolved.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to UIActivityViewController cannot save plist to local application's Documents
In fact the first popover displays fine, however when I choose Save to file, a new popover comes from bottom and immediately closes down (I havent't time to see its content).  Sorry, but I cannot reproduce the issue. I haven't implemented UIDocumentInteractionControllerDelegate nor set activityViewController.completionWithItemsHandler, but can see the second popover stable there. Maybe sort of view hierarchy is affecting. You may need to clarify what is needed to reproduce the issue.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’21
Reply to Protocol Not Working
I intialized my delegate to not be nil  Hidden parts of your code may be affecting. For example, The actual instance of the view controller running sendData() may not be the same instance you initialized. If you could show enough code, we would not need such guess game.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to UIActivityViewController cannot save plist to local application's Documents
As far as I tried, I could save a file using UIActivityViewController with the same settings in Info.plist. My app name appears under On My iPhone after choosing Save to Files, very similar to UIDocumentPickerViewController. I also would like to be able for the user to select/change the file name User can tap the name where save button is active, to rename the saved file. [ShareSheet] cancelled request - error: The operation couldn’t be completed. Invalid argument I could not reproduce this error. Have no idea what's affecting.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jan ’21
Reply to Search in an array
Swift Array has many methods to search, an example: let searchIdNumber = 2 if let foundHorse = myHorses.first(where: {$0.idNumber == searchIdNumber}) { &#9;&#9;print(foundHorse.name) } else { &#9;&#9;print("Not Found") } Better check the part Finding Elements in the documentation of Array - https://developer.apple.com/documentation/swift/array.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21