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
Post
Replies
Boosts
Views
Activity
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
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
Hello,
I’m looking for a MacBook Pro to develop app for Apple Store.
13-inch M2 MacBook Pro with 16gb ram and 1tb ssd is reasonable to develop app?
or any other suggestions?
I want to know how do you think about this.
thanks,
c00012
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
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
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
Hi,
I'm planning iOS app uses covers following functions:
write excel file(.xlsx)
read excel file (.xlsx) and show it on the table
I've been looking for library that can cover these so far, but I couldn't.
if someone recommends me any library, I'd be very appreciated.
thanks,
c00012
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
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
Hello,
I have a view has two textfields(a and b) and a button.
I want to move focus between textfields using enter key. that is;
enter value on a -> presss enter key -> enter value on b
How can I do it in swiftUI?
if someone give me an advice about it, I'd de very appreciated.
thanks,
c00012
Hello,
I have a view has a textfield.
I want to limit input on it to only letters and put up an alert dialog if anything other than letters.
if anyone give me a good advice about it, I'd be very appreciated.
thanks,
c00012
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
I'm in trouble in posting a question on SwiftUI forum.
I had revised text and tried several times to post it, but it didn't work.
There is nothing in my query that is remotely ‘sensitive’.
I don’t know what to do next.
Thanks in advance for any advice.
Regards,
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