Relative Content

Tag Archive for swift

string to int not giving desired output

print(“int==1.0–(Int(“1.0″) ?? 0)”) print(“int==1–(Int(“1″) ?? 0)”) Output I am getting int==1.0–0 int==1–1 Output I am expecting int==1.0–1 int==1–1 Any idea why first line is not giving output as 1 Note : print(“int==1–(Int(1.0) )”) This give output as 1. swift 1 The reason is that “1.0” is not a valid string representation of an integer so […]

Swift: Guard let propertyName else {return}?

I am new to swift. I have a class which has an optional property called name. In one of the class function, I want to unwrapped it using guard. I initially thought about this:

Issue with passing variable from one view (accessed from a NavigationLink) to the parent view

I’m learning Swift and am trying to experiment. I’m trying to access a variable and pass it from a subview in a NavigationLink. The variable is selected/controlled from a list within the view in the NavigationLink, and I want it to be passed back to the main screen view (ContentView) for use in code there. I’ve tried using @Binding and @State, but I keep getting an error at the bottom of the ContentView file saying “Missing argument for parameter ‘selection’ in call”. Can someone help?

in swift, each case under enum should string or rawValue

I would like to create one enum that each case present its own value. so I can use something like Fruit.apple /// apple. However at some point, I have the impression that it is not suitable to use rawValue. what is the suggestion? should i create a property like Fruit.apple.string or just use Fruit.apple.rawValue?

Type ‘MetalViewRepresentable’ does not conform to protocol ‘NSViewRepresentable’

Error Type ‘MetalViewRepresentable’ does not conform to protocol ‘NSViewRepresentable’ and Reference to invalid associated type ‘NSViewType’ of type ‘MetalViewRepresentable’ Question Not sure why this is happening, but I think issue is not the code but something with my targets I think. I’ve set up a brand new MacOS application and pasted this code and it […]