I have a file called eegsnapshot.swift which reads values from an EEG Sensor and stores them in a dictionary (I think?). I am having trouble trying to access these values. I am new to Swift and have done some work with Arrays and Dictionaries but the method used here is more complicated than what I have come across before.
Can anyone give me some insight into accessing a value from the dictionary, for example "eegDelta"?
I am hoping to use these values to control animations in SceneKit but need to be able to access them first.
public struct EEGSnapshot {
public let delta: Int
public let theta: Int
public let lowAlpha: Int
public let highAlpha: Int
public let lowBeta: Int
public let highBeta: Int
public let lowGamma: Int
public let highGamma: Int
public static let allZeros = EEGSnapshot()
public init(dictionary: NSDictionary = [:]) {
func extractPoint(key: String) -> Int {
return dictionary[key] as? Int ?? 0
}
delta = extractPoint("eegDelta")
theta = extractPoint("eegTheta")
lowAlpha = extractPoint("eegLowAlpha")
highAlpha = extractPoint("eegHighAlpha")
lowBeta = extractPoint("eegLowBeta")
highBeta = extractPoint("eegHighBeta")
lowGamma = extractPoint("eegLowGamma")
highGamma = extractPoint("eegHighGamma")
}
}
public extension NSDictionary {
public convenience init(eegSnapshot: EEGSnapshot) {
self.init(objects: [eegSnapshot.delta, eegSnapshot.theta, eegSnapshot.lowAlpha, eegSnapshot.highAlpha, eegSnapshot.lowBeta, eegSnapshot.highBeta, eegSnapshot.lowGamma, eegSnapshot.highGamma],
forKeys: ["eegDelta", "eegTheta", "eegLowAlpha", "eegHighAlpha", "eegLowBeta", "eegHighBeta", "eegLowGamma", "eegHighGamma"],
count: 8)
}
}
I've tried
var deltaValue = EEGSnapshot["eegDelta"]
and similar but I get the error "Type EEGSnapshot.Type has no subscript members".