Rucrazia's Blog
Swift 클래스에서 외부 클래스 참조 하는 방법 본문
Abstract
Class -> 함수 가져올때.
Struct -> 변수 가져올때. (받는 클래스에 클래스 선언 필요)
Main
Class로 묶어서 한다.
SensorTag.swift
class SensorTag {
// Check if the characteristic has a valid config UUID
class func validConfigCharacteristic (characteristic : CBCharacteristic) -> Bool {
if characteristic.UUID == IRTemperatureConfigUUID || characteristic.UUID == AccelerometerConfigUUID ||
characteristic.UUID == HumidityConfigUUID || characteristic.UUID == MagnetometerConfigUUID ||
characteristic.UUID == BarometerConfigUUID || characteristic.UUID == GyroscopeConfigUUID {
return true
}
else {
return false
}
class func validConfigCharacteristic (characteristic : CBCharacteristic) -> Bool {
if characteristic.UUID == IRTemperatureConfigUUID || characteristic.UUID == AccelerometerConfigUUID ||
characteristic.UUID == HumidityConfigUUID || characteristic.UUID == MagnetometerConfigUUID ||
characteristic.UUID == BarometerConfigUUID || characteristic.UUID == GyroscopeConfigUUID {
return true
}
else {
return false
}
}
}
class func getAccelerometerData(value: NSData) -> [Double] {
let dataFromSensor = dataToSignedBytes8(value)
let xVal = Double(dataFromSensor[0]) / 64
let yVal = Double(dataFromSensor[1]) / 64
let zVal = Double(dataFromSensor[2]) / 64 * -1
return [xVal, yVal, zVal]
let dataFromSensor = dataToSignedBytes8(value)
let xVal = Double(dataFromSensor[0]) / 64
let yVal = Double(dataFromSensor[1]) / 64
let zVal = Double(dataFromSensor[2]) / 64 * -1
return [xVal, yVal, zVal]
}
ViewController.swift
if SensorTag.validConfigCharacteristic(thisCharacteristic) {
// Enable Sensor
self.sensorTagPeripheral.writeValue(enablyBytes, forCharacteristic: thisCharacteristic, type: CBCharacteristicWriteType.WithResponse)
// Enable Sensor
self.sensorTagPeripheral.writeValue(enablyBytes, forCharacteristic: thisCharacteristic, type: CBCharacteristicWriteType.WithResponse)
}
let allValues = SensorTag.getAccelerometerData(characteristic.value!)
---------------------------------------------------------------------------------------
class Ble.swift
struct PropertyKey {
static let nameKey = "name"
static let identifierKey = "identifier"
static let ratingKey = "rating"
static let nameKey = "name"
static let identifierKey = "identifier"
static let ratingKey = "rating"
}
이렇게 씌워 놓고, 외부에서 둘 중 하나의 방식으로 선언한다.
전자는 배열식으로 nameKey,identifierKey, ratingKey를 인풋으로 받는것.
후자는 각각 ble.nameKey이렇게 받는것.
var bles = [Ble]()
var ble : Ble?
'기술 - Coding > Swift(iOS)' 카테고리의 다른 글
IOS LAYOUT (0) | 2016.07.27 |
---|