I want to import text from TextField(SwiftUI) in float format but I just have this error, the message said “Can’t turn the number of type ‘float’ to a unexpected type ‘Binding’”, if I try to run it will also send me the same error, how do I fix it?
As a swift noob, and coming from C++, I wonder why the following prints 'BOOM!!':
var text = ""
class ArrayHandle {
var array = Array()
init() {
text = "success"
}
deinit {
text = "BOOM!!"
}
}
struct Array { var buffer = Buffer() }
struct Buffer { func doStuff() { print(text)} }
var buffer = ArrayHandle().array.buffer.doStuff()
Apparently the deinit is called before the text is printed...
When you change the code to:
var handle = ArrayHandle()
handle.array.buffer.doStuff()
it prints the expected 'success'
Is there a way to force developers to use a var to store an object, or is that just a hidden bug that may fail in the future?
Post not yet marked as solved
Hello, I've been attempting to generate this code, but the last line returns an Expected declaration Error.
class AboutMe {
let firstName: String
let lastName: String
let age: Int
init(firstName: String, lastName: String, age: Int){
self.firstName = firstName
self.lastName = lastName
self.age = age
}
var me: String {
return "First Name: \(firstName), / Last Name: \(lastName), / Age: \(age)"
}
let myInfo = AboutMe(firstName: "NAME", lastName: "NAME", age: 10)
print(myInfo)
}