Andrew Fletcher published: 16 April 2023 1 minute read
Creating a foreach loop such as
var maxDigits: Int = 5
private var pinDots: some View {
HStack {
ForEach(0..<maxDigits) { index in
ZStack {
Image(systemName: self.getImageName(at: index))
.font(.system(size: 50.0, weight: .thin, design: .rounded))
.foregroundColor(.white)
.background(
index < pin.count ?
Color.black.opacity(0.8) :
.clear).cornerRadius(35.0)
}
.padding([.leading, .trailing], 4.0)
}
}
}
The integer maxDigits is showing an error 'Non-constant range: argument must be an integer literal'
Even though a let or var in this instance may not be the same as a literal, its value can never change so it's constant. Subsequently, the range created from from a literal when pass into ForEach.init(_:) are both the same constant range.
Alter the ForEach line as follows
ForEach(0..<maxDigits, id: \.self) { index in
Related articles
Andrew Fletcher
•
17 Dec 2023
Ignoring ffi-1.16.3 because its extensions are not built. Try: gem pristine ffi --version 1.16.3
The error you're encountering indicates an issue with the ffi gem during the CocoaPods update. The error message suggests trying to run the gem pristine command to fix it.Using terminal - run the following command:gem pristine ffi --version 1.16.3This command will attempt to restore the ffi gem to...
Andrew Fletcher
•
12 Aug 2022
Using SwiftUI URLComponent to change a URL's scheme
The challenge I was facing, I had written a script to scan barcodes and use Google book API to view the contents. However, a snippet of the JSON response
{
"contentVersion": "0.2.0.0.preview.0",
"panelizationSummary": {
"containsEpubBubbles": false,
...
Andrew Fletcher
•
19 Jul 2022
Xcode NullInjectorError
In Xcode and executing a run command, the response error was:
{
"name": "NullInjectorError",
"ngTempTokenPath": null,
"ngTokenPath": ["Ee", "fe", "Ne", "Ne", "Ne"]
}
This was a result of me attempting to incorrectly import the AppComponent from inside a service.
import {...