Post

Replies

Boosts

Views

Activity

Reply to What's the best way to know when a user is editing a SecureField in SwiftUI?
you could try something like this: &#9;&#9;&#9;&#9;&#9;&#9;@State var theText = "" &#9;&#9;&#9;&#9;&#9;&#9;@State var isInSecureField = false &#9;&#9;&#9;&#9;&#9;&#9;SecureField("enter your password", text: Binding<String>( &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;get: { self.theText }, &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;set: { self.theText = $0 &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("editing a SecureField") self.isInSecureField = true&#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:
Sep ’20
Reply to Pair this http post code with a button in Xcode
What errors do you get when you create a new project? What system are you using? You can do the following to setup a button to send a request. Note: you need to use "https" otherwise you will have to fiddle with the security entitlements. import SwiftUI &#9; struct ContentView: View { &#9;&#9;var body: some View { &#9;&#9; Button(action: {sendHttpPost()}) { &#9;&#9;&#9;&#9;Text("Press here to send a post") .padding(15) .foregroundColor(.blue) .border(Color.blue, width: 2) }.buttonStyle(PlainButtonStyle()) } func sendHttpPost() { let session = URLSession(configuration: .default) let url = URL(string: "http:...//ServerIP:8000/xmlcommand")! var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("text/plain", forHTTPHeaderField: "Content-Type") // I guess this can be "text/xml" // Working line request.httpBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Commands><command type=\"open\"><name>environments/Animals.hwe</name><id>a1</id></command></Commands>".data(using: .utf8) let task = session.dataTask(with: request) { data, response, error in // print(data as Any) // print(response as Any) // print(error as Any) // do something with the result print(data as Any? as Any) if let data = data { print(String(data: data, encoding: .utf8)!) } else { print("no data") } } task.resume() // <- otherwise your network request won't be started } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to Xcode Error is Not Making Sense
yes errors messages are often not very clear. To solve your problem try fix your code such as:  Note using macos 11 or ios 14, SwiftUI 2.0   &#9;&#9;&#9;struct Gamefile: View {   &#9;&#9;@State var randomNumber = Int.random(in: 1...100)   &#9;&#9;@State var sliderNumber = 1.0 // <-- is Double     &#9;&#9;&#9; var min = 1.0  // <-- must be Double  &#9;&#9;  var max = 100.0 // <-- must be Double       &#9;&#9;var body: some View {   &#9;   VStack {       Slider(value: $sliderNumber, in: min...max)       Button(action: {}, label: {         Text("Tap For Results!")           .padding()          //  .fontWeight(.heavy) // <-- no fontWeight           .font(.title3)           .background(Color.yellow)           .cornerRadius(30.0)           .shadow(radius: 5)  // <-- use this          //  .shadowRadius(5.0) // <-- no shadowRadius    &#9;&#9;   })   &#9;&#9;   }  &#9;&#9;&#9;  } &#9;&#9;&#9;&#9;}
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to Main menu in SwiftUI App
Use the .commands modifier, such as:&#9;@main &#9;struct MyApp: App { &#9;var body: some Scene { &#9;&#9;WindowGroup { &#9;&#9;&#9;&#9;ContentView() }.commands { CommandGroup(replacing: .help) { Button(action: {....}) { Text("MyApp Help") } } CommandMenu("Edit") { ... } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20
Reply to Main menu in SwiftUI App
I cannot replicate your error, all is working fine for me on: macos 11, using xcode 12. What system are you using? @main struct MyApp: App { var body: some Scene { &#9;&#9;WindowGroup { &#9;&#9;&#9;&#9;ContentView() }.commands { CommandGroup(replacing: .help) { Button(action: {print("clicked on MyApp Help menu")}) { Text("MyApp Help") } } CommandMenu("Edit") { Text("edit menu item") } } } } struct ContentView: View { var body: some View { Text("test").padding() } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’20