UPDATE이는 switch
문에 if-else
마이그레이션에서Swift 3의 switch 문에서 형식 유추가 작동하지 않는 이유는 무엇입니까?
스위프트 3.1에 고정되어, 그 형식 유추가 작동하지 않는 나타났습니다. quantityTypeIdentifier
이 이미 해당 유형 인 경우 각 case
에 HKQuantityTypeIdentifier
을 지정해야하는 이유는 무엇입니까?
func process(samples: [HKSample]?, quantityTypeIdentifier: HKQuantityTypeIdentifier) {
DispatchQueue.main.async { [weak self] in
if let quantitySamples = samples as? [HKQuantitySample] {
for sample in quantitySamples {
switch quantityTypeIdentifier {
case HKQuantityTypeIdentifier.distanceWalkingRunning:
// code
case HKQuantityTypeIdentifier.activeEnergyBurned:
// code
case HKQuantityTypeIdentifier.heartRate:
// code
default:
fatalError("Quantity Type Identifier not implemented \(quantityTypeIdentifier)")
}
}
}
}
}
내가 좋아하는 함수를 호출 할 수 있어요 :
process(samples: samples, quantityTypeIdentifier: .distanceWalkingRunning)
'HKQuantityTypeIdentifier'는 열거 형이 아닙니다. 그것은 구조체입니다. 아마 그럴 것입니다. – vadian
Swift 책에서 아무것도 찾을 수 없었지만,'quantityTypeIdentifier == .distanceWalkingRunning {}'이 작동하면 switch 문도이를 처리 할 수 있어야합니다. – jjatie
이'struct '가 Obj-C와의 호환성을위한'enum'이 아닌 이유는 무엇입니까? – jjatie