I'm working on a function that generates "random numbers" that works okay, but the implementation leaves things that need to migrated to a class. The class may work, but I'm trying to create three empty arrays of type Int but I'm trying to understand the code errors while I'm working on the rest of the code. I was copying the first one to the net two changing the names trying to understand the error message.
I'm sorry to be a noob, I'm an older programmer and pretty new to Swift (3 or 4@nbsp;years with long breaks of not working on code) - BTW I can regale anyone you with tales of FORTRAN, C, PDP-11 & VAX assembler, TCL/TK, etc.
- /Users/wayned1/devel/experim2/encryptor/encryptor/main.swift:21:21 Cannot convert value of type 'Array' to specified type 'Int'
- /Users/wayned1/devel/experim2/encryptor/encryptor/main.swift:22:21 Cannot convert value of type '[Any]' to specified type 'Int'
- the last is duplicated (obviously) - I'm trying to puzzle it out
class GenRandom {
// properties
var vec1: Int = Array()
var vec2: Int = []
var vec3: Int = []
// initialization
init(name: String, age: Int) {
let fileContents = try String(contentsOfFile: filePath, encoding: .utf8)
// Create a scanner to parse the file contents
let scanner = Scanner(string: fileContents)
var numbers: [Int] = []
// Scan for integers
while !scanner.isAtEnd {
var number: Int = 0
if scanner.scanInt(&number) {
numbers.append(number)
} else {
// If unable to scan an integer, move scanner to the next token
// scanner.scanUpToCharacters(from: CharacterSet.decimalDigits, into: nil)
}
}
} catch {
// Handle the error if the file cannot be read
print("Error reading file: (error)")
return nil
}
// self.name = name
// self.age = age
};