Post

Replies

Boosts

Views

Activity

Question about using multiple NavigationLinks in same project
Hello, I want to write an app for following requirements: Four views(A,B,C and D) has navigationlink as a button to move to view E. so I wrote a navigationlink on view A as follows: NavigationLink(destination: DestinationView(result: iOSVM.add(a: (Int(numberA) ?? 0), b: (Int(numberB) ?? 0)))) { Text("Add?") } and another navigationlink on view B like this: NavigationLink(destination: DestinationView(result:iOSVM.subtract(a:number1,b:number2))){ Text("Result?") } after running these codes, navigationlink on view A works properly. but another one on view B remains diabled. help me to fix this. thx, c00012
1
0
294
Jul ’24
Question about preview using code in SwiftUI
Hello, I have a view which have a few controls and preview macro. I replaced preview macro with following code: struct ContentView_Preview:PreviewProvider{ static var previews: some View{ ContentView() } } after replacement, preview doesn't work properly. plz tell me how can i fix it. thanks, c00012
2
0
345
Jul ’24
How can I pass value from TextField to Alert?
Hello, I have a view has 4 textfields and a button. I want to show 4 values from textfields on popup messagebox. so I wrote a following codes. @State private var lender = "" @State private var amount = "" @State private var rate = "" @State private var duration = "" Button(action: {showingAlert = true}, label: { Text("Inputs") .padding() .background(RoundedRectangle(cornerRadius: 10).strokeBorder()) }).padding(10) .accentColor(.green) .alert("Inputs", isPresented: $showingAlert){ Text("Lender: \(lender)").font(.title3) Text("Amount:\(amount)").font(.title3) Text("Rate:\(rate)") Text("Duration:\(duration)") Button("OK", role: .cancel){} } When I run this code, Alert popped up but there's no values. If someone point my mistakes, I'd very appreciated. thanks, c00012
1
0
309
Jun ’24
Question about textfield
Hello, I have a view have three textfields and a button. I wrote following code to move between textfields using return key. func textFieldShouldReturn(_ textField: UITextField) -> Bool { if textField == self.A { self.B.becomeFirstResponder() }else if textField == self.B { self.C.becomeFirstResponder() } return true } when I use return key between A->B, above code works properly. but when i use return key between B->C, above code doesn't work. I couldn't figure out what's wrong with this. if anyone pick me my mistake and suggest solution for it, I'd very appreciate. Thanks, c00012
2
0
410
May ’24
Question about build an iOS project in Xcode 15.2
Hello, I have a question about building a project in Xcode 15.2. When I build an iOS project in Xcode 15.2, I get a message like this: "Assets.xcassets: Could not get trait set for device iPad14,3 with version 17.2" though I have no trouble in building and running a project, I want to fix this. If anyone solve problem like this, please let me know how to fix it. thanks, c00012
1
0
978
Feb ’24
Question about Property Observer
I'm studying swift to develop macOS app so far. I wrote a following code to learn property observer. var x:Int var y:Int var oppositePos:coordinatePoint{ get{ coordinatePoint(x: -x, y: -y) } set{ x = -newValue.x y = -newValue.y } } } I want to implement property observer on opposites property so I changed code as follows : var x:Int var y:Int var oppositePos:coordinatePoint { willSet{ print("\(oppositePos) is changed to \(newValue)") } didSet{ print("\(oldValue) is changed to \(oppositePos)") } } } after changing code, I ran it but I got following error messages: Value type 'coordinatePoint' cannot have a stored property that recursively contains it Missing argument for parameter 'oppositePos' in call My question: property observer is available on this property? if so, what should I change in this code? if someone give me an advice to fix errors, I'd be very appreciate. thanks, c00012
3
0
409
Jul ’23
question about self-refer in swift structure
Hello, I have a question about self-refer in using structure in swift. I want to use structure to implement Node. so I wrote code like this; public struct Node { var Data:Int = 0 var next:Node? } I've got an error message says: Value type 'Node' cannot have a stored property that recursively contains it. the question is: self-refer is impossible in swift? if someone give me an advice about this, I'd be very appreciated. thanks, c00012
1
0
440
Mar ’23
Question about String.Index
Hello, I wrote a code to get second character of the string as follows: print("name:") let name = readLine()! print("Age:") let age = Int(readLine()!)! print("Name:\(name), Age:\(age)") let idx = name.index(name.startIndex, offsetBy: 1) print(name[idx]) print(idx) I entered these to test this code; name: John age:20 I expected result: name:John age:20 o 1 but I got: name:John age:20 o Index(_rawBits: 65799)//I expected 1 If someone can explain why I can't get index number of the string, I'd be very appreciated. thanks for your answer in advance. c00012
1
0
432
Nov ’22
Question about Conversion from decimal to double
Hello, I have a question while I was coding in swift. I wrote a following code: import Foundation protocol feature{     func getPayment(o:Offer)->Double } enum ProdCode{     case PersonalLoan     case Mortgage     case AutoLoan } struct Offer{     var Code:ProdCode     var Lender:String     var LoanAmt:Double     var APR:Double     var Terms:Int } class A: feature {     func getPayment(o: Offer)->Double {         var PLfactor = o.APR / 100 / 12         var PLfogr = pow(Decimal(1 + PLfactor), o.Terms * 12)         return o.LoanAmt * PLfactor * (PLfogr / (PLfogr) - 1)     } } I got an error message saying "Cannot convert value of type 'Decimal' to expected argument type 'Double'" from the line 'return o.LoanAmt * PLfactor * (PLfogr / (PLfogr) - 1)'. if someone pick what my fault is in the line, I'd be very appreciated. thanks for your answer in advance. c00012
1
0
437
Nov ’22
Question about protocol
Hello, i have a question while writing a code. I want to use protocol with the class as follows: protocol: protocol feature{     func getPayment(o:Offer)     func Amortize(o:Offer)     func Export() } class: class LoanBase: feature {     func getPayment(o: Offer) {         var PLFactor = o.APR / 100 / 12         var PLfogr = pow(1 + PLFactor , o.Terms*12)     } } I got an following error message: "Type 'LoanBase' does not conform to protocol 'feature'" if someone pick my mistake, I would be very grateful to him. thanks, c00012
1
0
360
Oct ’22