Post

Replies

Boosts

Views

Activity

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 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
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 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 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: 		func generateQRCodeImage(url : String) -> UIImage { 				let data = Data(url.utf8) 				filter.setValue(data, forKey: "inputMessage") 				 				if let qrCodeImage = filter.outputImage { 						if let cgImage = context.createCGImage(qrCodeImage, from: qrCodeImage.extent) { 								return UIImage(cgImage: cgImage) 						} 				} 				return UIImage(systemName: "xmark") ?? UIImage() 		} CGImage is the type to represent a bitmap based image.
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 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 Using Bindings with (Arrays of) Enumerations
If you would not mind defining a read-write computed property, you can write something like this: extension Row { &#9;&#9;var textBody: String { &#9;&#9;&#9;&#9;get { &#9;&#9;&#9;&#9;&#9;&#9;switch self { &#9;&#9;&#9;&#9;&#9;&#9;case .text(let body): &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return body &#9;&#9;&#9;&#9;&#9;&#9;default: &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;return "" &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;mutating set { &#9;&#9;&#9;&#9;&#9;&#9;self = .text(newValue) &#9;&#9;&#9;&#9;} &#9;&#9;} } struct StuffView: View { &#9;&#9;@State var stuff: [Row] = [.text("foo"), .text("bar")] &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;List { &#9;&#9;&#9;&#9;&#9;&#9;ForEach(stuff.indices) { idx in &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;switch stuff[idx] { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;case .text(let body): &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;HStack { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;TextField( &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;"Row \(idx)", &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;text: $stuff[idx].textBody //<- &#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;Spacer() &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;Text(body) &#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;} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Protocol Not Working
I have an identifier I named r in the storyboard. That has no meaning. Even if you have a segue with identifier r, you need to properly invoke it. By the way, print("segue identifier", segue.identifier) needs to places outside of if-statement to explore what's happening to your project.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21