I cannot help with your current problem, but let me give a few pointers that may lead you towards the solution.
You seem to be receiving some kind of BanklList and FrequencyData from different IP addresses and then parse it to few dozen variables. This is not a good solution, you will stumble to the amount of variables and trying to do several things at once.
I would propose you find a way to organise the data in a bit more structured way. This will help you to divide and conquer the problem space, separating different parts of code in smaller parts that are easier to test and debug.
To me it looks like the main entities are Host, FrequencyPacket and BanklistPacket. One way to model this might be following.
struct Host {
var name: String
var returnCh1, returnCh2, returnCh3, returnCh4: Bool
}
class Packet { }
class FrequencyPacket: Packet {
let frequency, bank, ch: Int
init(frequency: Int, bank: Int, ch: Int) {
self.frequency = frequency
self.bank = bank
self.ch = ch
}
}
class BanklistPacket: Packet {
let hz1, hz2, hz3, hz4: String
init(hz1: String, hz2: String, hz3: String, hz4: String) {
self.hz1 = hz1
self.hz2 = hz2
self.hz3 = hz3
self.hz4 = hz4
}
}
You should parse one packet at a time something like following and write tests that ensure your parsing code.
func parse(string: String) -> Packet? {
let data = string.split(separator: " ")
let packageType = data[0]
switch packageType {
case "BankList":
return BanklistPacket(
hz1: String(data[2]),
hz2: String(data[3]),
hz3: String(data[4]),
hz4: String(data[5]))
case "Frequency":
guard
let frequency = Int(data[2]),
let bank = Int(data[3]),
let ch = Int(data[4])
else { return nil }
return FrequencyPacket(frequency: frequency, bank: bank, ch: ch)
default:
return nil
}
When you have parsed the data in an easier to handle form, and have your Hosts stored in an array or such. The probability of getting forward increases.
Disclaimer: I did not think this fully thru nor test. And I may have misunderstood your project.