Post

Replies

Boosts

Views

Activity

NSObject @objc dynamic class with SwiftUI
Hello, I'm using PaintCode for UIGraphics which exports Swift files with an @objc dynamic public class func nested in a NSObject class. With older versions of Swift, could be implemented with the use of a UIKit view and the storyboard. How could I do this with SwiftUI? Thanks in advance.
1
0
868
Mar ’21
Previewing view with Binding variable
Hello, I'm having trouble previewing a view that has a binding variable. When it's in the below state, I get the error "Edit placeholder in source file": static var previews: some View { Navigation(viewState: Binding<String>) } } When I put a string as a placeholder, I get the error: Cannot convert value of type 'String' to expected argument type 'Binding' static var previews: some View { Navigation(viewState: "sign-in") } } The code for the supporting view with the binding variable is below: struct Navigation: View { @Binding var viewState: String var body: some View { ZStack { HStack { Spacer() Button(action: { toggleView(view: "savings")}) { Text("Savings") } Spacer() Button(action: { toggleView(view: "settings")}) { Text("Settings") } Spacer() } } .position(x: UIScreen.main.bounds.width / 2, y: UIScreen.main.bounds.height / 2) .frame(width: UIScreen.main.bounds.width, height: 100) } func toggleView(view: String) { viewState = view } } Any help would be greatly appreciated.
1
0
1.1k
Dec ’23
Cannot convert value of type '() -> ()' to expected argument type 'String' SwiftUI Button
Hello, I'm trying to build a simple button. For some reason, I'm getting the following errors: Cannot convert value of type '() -> ()' to expected argument type 'String' Incorrect argument label in call (have 'action:_:', expected 'value:selected:') Button(action: login) { ZStack { RoundedRectangle(cornerRadius: 5) .fill(Color.black) .frame(width: UIScreen.main.bounds.width - 50, height: 50) Text("Sign in") .foregroundColor(.white) } } All of my buttons in this particular project suddenly have this error. Any help would be greatly appreciated. Thank you
3
0
1.4k
Dec ’23
Using Swift UI Canvas
Hello, I am trying to use the SwiftUI canvas and I'm having a couple of issues. One is that I'd like to be able to fit a canvas view in a ScrollView, but when the canvas is inside a ScrolLView, nothing draws. Additionally, I'm trying to draw lines on the canvas on Appear, but I can't seem to get that to work either. Below is a simplified version of the code I have: struct Line: Codable, Hashable { var points: [CGPoint] var colorName: String? var rgb: [Double]? private enum CodingKeys: String, CodingKey { case points case colorName case rgb } } extension CGPoint: Hashable { public func hash(into hasher: inout Hasher) { hasher.combine(x) hasher.combine(y) } } struct CanvasExample: View { @State var lines: [Line] = [] @State var selectedColor: Color = Color.black var body: some View { Canvas { ctx, size in for line in lines { var path = Path() path.addLines(line.points) ctx.stroke(path, with: .color(line.color), style: StrokeStyle(lineWidth: 5, lineCap: .round, lineJoin: .round)) } }.gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local) .onChanged({ value in let position = value.location if value.translation == .zero { lines.append(Line(points: [position], color: selectedColor)) } else { guard let lastIndex = lines.indices.last else { return } lines[lastIndex].points.append(position) } }) ) .onAppear { lines.append(Line(points: [position], color: .black)) } } } Any help would be greatly appreciated. Thank you.
4
0
1.3k
Jan ’24
Getting started with App Store Server API and programmatically cancelling a user's subscription
Hello, I'm inquiring in regard to information on handling user's subscriptions, specifically if it's possible to cancel a subscription with a line of code. For example: if condition { // cancel user's subscription } I'm not familiar with the App Store Server API yet, but I glanced at the documentation and I didn't see any information in regard to the question I have. That being said, I'm also wondering where to start with configuring a subscription model for my app. Any insights would be greatly appreciated. Thank you.
1
0
1.3k
Feb ’24
Passing binding variable to function with optional parameter
Hi, I have a view that takes an optional binding boolean variable. I'd like to pass a variable to it from certain views only. The problem I'm having is when I pass a variable, I get the error "Cannot convert value of type 'Binding' to expected argument type 'Binding<Bool?>'", and when I don't, I get the error "Missing argument for parameter 'toggle' in call". Below Is the code I have. Thank you. Heading(text: "Heading1") // error: Missing argument for parameter 'toggle' in call Heading(text: "Heading2", toggle: $newEntry) // Cannot convert value of type 'Binding<Bool>' to expected argument type 'Binding<Bool?>' struct Heading: View { @State var text: String @Binding var toggle: Bool? var body: some View { VStack { Spacer() .frame(height: 25) HStack { Text(text) .font(.system(size: 36)) Spacer() if text == "str" { Button(action: { toggle!.toggle() }) { Image(systemName: "plus") .foregroundColor(.black) .font(.system(size: 36)) } } } Spacer() .frame(height: 25) } } }
0
0
848
Apr ’24
RFID connection between iPhones
Hi, I'm inquiring in regards to the feasibility or possibility of making a connection from iPhone to another, such that one iPhone uses Apple wallet, and another iPhone would detect for the signal within the app. Please let me know if this is feasible or if any more information would be necessary to assist. If this is possible, what documentation would be relevant? Thank you.
1
0
599
Jul ’24
Undefined symbol and linker command failed errors
Hi, I was searching and replacing code where all of the sudden I got the following errors: Undefined symbol: AppName.Client.init(id: Swift.Int, name: Swift.String, StructVariable: Swift.Int?, structVariable: [Struct]?) -> AppNameStruct Linker command failed with exit code 1 (use -v to see invocation) I replaced the names in the first error message for privacy reasons. I tried quitting Xcode and restarting my computer but the error persisted. Any help on resolving this would be greatly appreciated.
Topic: Design SubTopic: General Tags:
1
0
804
Aug ’24
Condensing HTTP request functions
Hi, For HTTP requests, I have the following function: func createAccount(account: Account, completion: @escaping (Response) -> Void) { guard let url = URL(string: "http://localhost:4300/account") else { return } var request = URLRequest(url: url) request.httpMethod = "POST" request.setValue("application/json", forHTTPHeaderField: "Content-Type") guard let encoded = try? JSONEncoder().encode(account) else { print("Failed to encode request") return } request.httpBody = encoded URLSession.shared.dataTask(with: request) { (data, response, error) in guard let data = data else { return } do { let resData = try JSONDecoder().decode(Response, from: data) DispatchQueue.main.async { completion(resData) } } catch let jsonError as NSError { print("JSON decode failed: \(jsonError)") } }.resume() } Because various HTTP requests use different body structs and response structs, I have a HTTP request function for each individual HTTP request. How can I condense this into one function, where the passed struct and return struct are varying, so I can perhaps pass the struct types in addition to the data to the function? Any guidance would be greatly appreciated.
0
0
434
Aug ’24
Thread Error with @Model Class
I have a @Model class that is comprised of a String and a custom Enum. It was working until I added raw String values for the enum cases, and afterwards this error and code displays when opening a view that uses the class: { @storageRestrictions(accesses: _$backingData, initializes: _type) init(initialValue) { _$backingData.setValue(forKey: \.type, to: initialValue) _type = _SwiftDataNoType() } get { _$observationRegistrar.access(self, keyPath: \.type) return self.getValue(forKey: \.type) } set { _$observationRegistrar.withMutation(of: self, keyPath: \.type) { self.setValue(forKey: \.type, to: newValue) } } } Thread 1: EXC_BREAKPOINT (code=1, subcode=0x1cc165d0c) I removed the String raw values but the error persists. Any guidance would be greatly appreciated. Below is replicated code: @Model class CopingSkillEntry { var stringText: String var case: CaseType init(stringText: String, case: CaseType) { self.stringText = stringText self.case = case } } enum CaseType: Codable, Hashable { case case1 case case1 case case3 }
2
0
495
Oct ’24