수영앱을 만들면서 데이터를 쿼리한 결과를 가공하기 위한 데이터 분석
우선 지금까지 수영 기록중에서 가장 최근 데이터를 뽑아서 Rawdata를 분석해보았다.
HKWorkout
https://developer.apple.com/documentation/healthkit/hkworkout
// record는 [HKWorkout]타입
print("-------------------------------")
print("SWIM! Swimming Data를 가져왔습니다. \\(records)")
print("-------------------------------")
print("SWIM DEBUG duration: \\(records[0].duration)")
if #available(iOS 16.0, *) {
print("SWIM! allStatistics: \\(records[0].allStatistics)")
print("SWIM! workoutActivities: \\(records[0].workoutActivities)")
}
print("SWIM DEBUG workoutActivityType: \\(records[0].workoutActivityType)")
print("SWIM DEBUG workoutEvents: \\(records[0].workoutEvents)")
HKWorkout.duration
duration: 총 운동 시간을 나타냄 (단위: Second)
duration: 3254.731590986252 // 약 54분
HKWorkout.allStatistics (iOS 16+)
var allStatistics: [HKQuantityType : HKStatistics] { get }
데이터를 Dictionary형태로 나타냄. iOS 16이상.
수영 데이터에서는 RawData를 보아서는 수영거리, 스트로크 횟수, 휴식에너지, 활동에너지를 확인 할 수 있음.
아래 네가지 데이터타입을 받아서 사용하면 될 것으로 판단 됨.
- HKQuantityTypeIdentifierDistanceSwimming
- HKQuantityTypeIdentifierSwimmingStrokeCount
- HKQuantityTypeIdentifierBasalEnergyBurned
- HKQuantityTypeIdentifierActiveEnergyBurned
allStatistics:
[HKQuantityTypeIdentifierDistanceSwimming:
<<HKStatistics: 0x2816f0820>
Statistics on HKQuantityTypeIdentifierDistanceSwimming
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierSwimmingStrokeCount: <<HKStatistics: 0x2816f08f0>
Statistics on HKQuantityTypeIdentifierSwimmingStrokeCount
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierBasalEnergyBurned: <<HKStatistics: 0x2816f0a90>
Statistics on HKQuantityTypeIdentifierBasalEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierActiveEnergyB
urned: <<HKStatistics: 0x2816f0b60>
Statistics on HKQuantityTypeIdentifierActiveEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>]
HKWorkout.workoutActivities (iOS 16+)
HKWorkoutActivity는 운동 데이터별로 다양한 정보를 제공함.
workoutActivities:
[<HKWorkoutActivity 9B9EF1D0-42FD-4B5E-92F8-1D505D5CE5EC
<HKWorkoutConfiguration:0x2809d54a0
activity:HKWorkoutActivityTypeSwimming
location:outdoors swimming
location:pool
lap length:25 m>
2023-06-04 23:05:59 +0000 2023-06-05 00:00:14 +0000>]
HKWorkout.workoutActivityType
운동 타입을 나타냄. 당연하지만, 46번은 수영타입.
workoutActivityType: HKWorkoutActivityType(rawValue: 46)
HKWorkout.workoutEvents
workoutEvents | Apple Developer Documentation
운동시작 종료, 재개 등의 이벤트 데이터.
수영 앱에서는 랩타임, 휴식시간, 수영 스타일 등으로 활용 가능.
workoutEvents: Optional(
[HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62080>
(Start Date) 2023-06-04 23:06:00 +0000 +
(Duration) 621.031649 seconds =
(End Date) 2023-06-04 23:16:21 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62540>
(Start Date) 2023-06-04 23:16:03 +0000 +
(Duration) 18.785561 seconds =
(End Date) 2023-06-04 23:16:21 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeLap,
<_NSConcreteDateInterval: 0x282d625a0>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62620>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62660>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62600>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d626e0>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 14.534096 seconds =
(End Date) 2023-06-04 23:20:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62740>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 38.461768 seconds =
(End Date) 2023-06-04 23:20:28 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62780>
(Start Date) 2023-06-04 23:20:10 +0000 +
(Duration) 18.203081 seconds =
(End Date) 2023-06-04 23:20:28 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d629a0>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 41.486095 seconds =
(End Date) 2023-06-04 23:22:20 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62b20>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 53.803628 seconds =
(End Date) 2023-06-04 23:22:33 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62b80>
(Start Date) 2023-06-04 23:22:21 +0000 +
(Duration) 11.276112 seconds =
(End Date) 2023-06-04 23:22:33 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62c00>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62c60>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63300>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 15.085003 seconds =
(End Date) 2023-06-04 23:25:23 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63340>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 72.507750 seconds =
(End Date) 2023-06-04 23:26:21 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d633a0>
(Start Date) 2023-06-04 23:25:32 +0000 +
(Duration) 48.531872 seconds =
(End Date) 2023-06-04 23:26:21 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63460>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63520>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d634c0>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63580>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63680>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d633e0>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63740>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63880>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63900>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63780>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63ac0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 42.347853 seconds =
(End Date) 2023-06-04 23:35:49 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d637e0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 79.904602 seconds =
(End Date) 2023-06-04 23:36:27 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63e80>
(Start Date) 2023-06-04 23:35:54 +0000 +
(Duration) 32.615227 seconds =
(End Date) 2023-06-04 23:36:27 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b480>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 48.341583 seconds =
(End Date) 2023-06-04 23:39:26 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d680a0>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 96.482671 seconds =
(End Date) 2023-06-04 23:40:14 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d69160>
(Start Date) 2023-06-04 23:39:34 +0000 +
(Duration) 40.684590 seconds =
(End Date) 2023-06-04 23:40:14 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6a240>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6a8e0>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6ba60>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b940>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b880>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000 {
HKSwimmingStrokeStyle = 5;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b6c0>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000])
HKWorkout
수영앱을 만들면서 데이터를 쿼리한 결과를 가공하기 위한 데이터 분석
우선 지금까지 수영 기록중에서 가장 최근 데이터를 뽑아서 Rawdata를 분석해보았다.
// record는 [HKWorkout]타입
print("-------------------------------")
print("SWIM! Swimming Data를 가져왔습니다. \\(records)")
print("-------------------------------")
print("SWIM DEBUG duration: \\(records[0].duration)")
if #available(iOS 16.0, *) {
print("SWIM! allStatistics: \\(records[0].allStatistics)")
print("SWIM! workoutActivities: \\(records[0].workoutActivities)")
}
print("SWIM DEBUG workoutActivityType: \\(records[0].workoutActivityType)")
print("SWIM DEBUG workoutEvents: \\(records[0].workoutEvents)")
HKWorkout.duration
duration | Apple Developer Documentation
duration: 총 운동 시간을 나타냄 (단위: Second)
duration: 3254.731590986252 // 약 54분
HKWorkout.allStatistics
allStatistics | Apple Developer Documentation
var allStatistics: [HKQuantityType : HKStatistics] { get }
데이터를 Dictionary형태로 나타냄. iOS 16이상.
수영 데이터에서는 RawData를 보아서는 수영거리, 스트로크 횟수, 휴식에너지, 활동에너지를 확인 할 수 있음.
아래 네가지 데이터타입을 받아서 사용하면 될 것으로 판단 됨.
HKQuantityTypeIdentifierDistanceSwimming
HKQuantityTypeIdentifierSwimmingStrokeCount
HKQuantityTypeIdentifierBasalEnergyBurned
HKQuantityTypeIdentifierActiveEnergyBurned
allStatistics:
[HKQuantityTypeIdentifierDistanceSwimming:
<<HKStatistics: 0x2816f0820>
Statistics on HKQuantityTypeIdentifierDistanceSwimming
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierSwimmingStrokeCount: <<HKStatistics: 0x2816f08f0>
Statistics on HKQuantityTypeIdentifierSwimmingStrokeCount
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierBasalEnergyBurned: <<HKStatistics: 0x2816f0a90>
Statistics on HKQuantityTypeIdentifierBasalEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierActiveEnergyB
urned: <<HKStatistics: 0x2816f0b60>
Statistics on HKQuantityTypeIdentifierActiveEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>]
HKWorkout.workoutActivities
HKWorkoutActivity는 운동 데이터별로 다양한 정보를 제공함.
workoutActivities | Apple Developer Documentation
workoutActivities:
[<HKWorkoutActivity 9B9EF1D0-42FD-4B5E-92F8-1D505D5CE5EC
<HKWorkoutConfiguration:0x2809d54a0
activity:HKWorkoutActivityTypeSwimming
location:outdoors swimming
location:pool
lap length:25 m>
2023-06-04 23:05:59 +0000 2023-06-05 00:00:14 +0000>]
HKWorkout.workoutActivityType
workoutActivityType: HKWorkoutActivityType(rawValue: 46)
HKWorkout.workoutEvents
workoutEvents | Apple Developer Documentation
운동시작 종료, 재개 등의 이벤트 데이터.
수영 앱에서는 랩타임, 휴식시간, 수영 스타일 등으로 활용 가능.
workoutEvents: Optional(
[HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62080>
(Start Date) 2023-06-04 23:06:00 +0000 +
(Duration) 621.031649 seconds =
(End Date) 2023-06-04 23:16:21 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62540>
(Start Date) 2023-06-04 23:16:03 +0000 +
(Duration) 18.785561 seconds =
(End Date) 2023-06-04 23:16:21 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeLap,
<_NSConcreteDateInterval: 0x282d625a0>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62620>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62660>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62600>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d626e0>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 14.534096 seconds =
(End Date) 2023-06-04 23:20:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62740>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 38.461768 seconds =
(End Date) 2023-06-04 23:20:28 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62780>
(Start Date) 2023-06-04 23:20:10 +0000 +
(Duration) 18.203081 seconds =
(End Date) 2023-06-04 23:20:28 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d629a0>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 41.486095 seconds =
(End Date) 2023-06-04 23:22:20 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62b20>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 53.803628 seconds =
(End Date) 2023-06-04 23:22:33 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62b80>
(Start Date) 2023-06-04 23:22:21 +0000 +
(Duration) 11.276112 seconds =
(End Date) 2023-06-04 23:22:33 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62c00>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62c60>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63300>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 15.085003 seconds =
(End Date) 2023-06-04 23:25:23 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63340>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 72.507750 seconds =
(End Date) 2023-06-04 23:26:21 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d633a0>
(Start Date) 2023-06-04 23:25:32 +0000 +
(Duration) 48.531872 seconds =
(End Date) 2023-06-04 23:26:21 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63460>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63520>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d634c0>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63580>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63680>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d633e0>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63740>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63880>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63900>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63780>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63ac0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 42.347853 seconds =
(End Date) 2023-06-04 23:35:49 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d637e0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 79.904602 seconds =
(End Date) 2023-06-04 23:36:27 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63e80>
(Start Date) 2023-06-04 23:35:54 +0000 +
(Duration) 32.615227 seconds =
(End Date) 2023-06-04 23:36:27 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b480>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 48.341583 seconds =
(End Date) 2023-06-04 23:39:26 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d680a0>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 96.482671 seconds =
(End Date) 2023-06-04 23:40:14 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d69160>
(Start Date) 2023-06-04 23:39:34 +0000 +
(Duration) 40.684590 seconds =
(End Date) 2023-06-04 23:40:14 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6a240>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6a8e0>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6ba60>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b940>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b880>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000 {
HKSwimmingStrokeStyle = 5;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b6c0>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000])
우선 지금까지 수영 기록중에서 가장 최근 데이터를 뽑아서 Rawdata를 분석해보았다.
// record는 [HKWorkout]타입
print("-------------------------------")
print("SWIM! Swimming Data를 가져왔습니다. \\(records)")
print("-------------------------------")
print("SWIM DEBUG duration: \\(records[0].duration)")
if #available(iOS 16.0, *) {
print("SWIM! allStatistics: \\(records[0].allStatistics)")
print("SWIM! workoutActivities: \\(records[0].workoutActivities)")
}
print("SWIM DEBUG workoutActivityType: \\(records[0].workoutActivityType)")
print("SWIM DEBUG workoutEvents: \\(records[0].workoutEvents)")
HKWorkout.duration
duration | Apple Developer Documentation
duration: 총 운동 시간을 나타냄 (단위: Second)
duration: 3254.731590986252 // 약 54분
HKWorkout.allStatistics
allStatistics | Apple Developer Documentation
var allStatistics: [HKQuantityType : HKStatistics] { get }
데이터를 Dictionary형태로 나타냄. iOS 16이상.
수영 데이터에서는 RawData를 보아서는 수영거리, 스트로크 횟수, 휴식에너지, 활동에너지를 확인 할 수 있음.
아래 네가지 데이터타입을 받아서 사용하면 될 것으로 판단 됨.
HKQuantityTypeIdentifierDistanceSwimming
HKQuantityTypeIdentifierSwimmingStrokeCount
HKQuantityTypeIdentifierBasalEnergyBurned
HKQuantityTypeIdentifierActiveEnergyBurned
allStatistics:
[HKQuantityTypeIdentifierDistanceSwimming:
<<HKStatistics: 0x2816f0820>
Statistics on HKQuantityTypeIdentifierDistanceSwimming
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierSwimmingStrokeCount: <<HKStatistics: 0x2816f08f0>
Statistics on HKQuantityTypeIdentifierSwimmingStrokeCount
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierBasalEnergyBurned: <<HKStatistics: 0x2816f0a90>
Statistics on HKQuantityTypeIdentifierBasalEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierActiveEnergyB
urned: <<HKStatistics: 0x2816f0b60>
Statistics on HKQuantityTypeIdentifierActiveEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>]
HKWorkout.workoutActivities
HKWorkoutActivity는 운동 데이터별로 다양한 정보를 제공함.
workoutActivities | Apple Developer Documentation
workoutActivities:
[<HKWorkoutActivity 9B9EF1D0-42FD-4B5E-92F8-1D505D5CE5EC
<HKWorkoutConfiguration:0x2809d54a0
activity:HKWorkoutActivityTypeSwimming
location:outdoors swimming
location:pool
lap length:25 m>
2023-06-04 23:05:59 +0000 2023-06-05 00:00:14 +0000>]
HKWorkout.workoutActivityType
workoutActivityType: HKWorkoutActivityType(rawValue: 46)
HKWorkout.workoutEvents
workoutEvents | Apple Developer Documentation
운동시작 종료, 재개 등의 이벤트 데이터.
수영 앱에서는 랩타임, 휴식시간, 수영 스타일 등으로 활용 가능.
workoutEvents: Optional(
[HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62080>
(Start Date) 2023-06-04 23:06:00 +0000 +
(Duration) 621.031649 seconds =
(End Date) 2023-06-04 23:16:21 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62540>
(Start Date) 2023-06-04 23:16:03 +0000 +
(Duration) 18.785561 seconds =
(End Date) 2023-06-04 23:16:21 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeLap,
<_NSConcreteDateInterval: 0x282d625a0>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62620>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62660>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62600>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d626e0>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 14.534096 seconds =
(End Date) 2023-06-04 23:20:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62740>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 38.461768 seconds =
(End Date) 2023-06-04 23:20:28 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62780>
(Start Date) 2023-06-04 23:20:10 +0000 +
(Duration) 18.203081 seconds =
(End Date) 2023-06-04 23:20:28 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d629a0>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 41.486095 seconds =
(End Date) 2023-06-04 23:22:20 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62b20>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 53.803628 seconds =
(End Date) 2023-06-04 23:22:33 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62b80>
(Start Date) 2023-06-04 23:22:21 +0000 +
(Duration) 11.276112 seconds =
(End Date) 2023-06-04 23:22:33 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62c00>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62c60>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63300>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 15.085003 seconds =
(End Date) 2023-06-04 23:25:23 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63340>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 72.507750 seconds =
(End Date) 2023-06-04 23:26:21 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d633a0>
(Start Date) 2023-06-04 23:25:32 +0000 +
(Duration) 48.531872 seconds =
(End Date) 2023-06-04 23:26:21 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63460>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63520>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d634c0>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63580>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63680>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d633e0>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63740>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63880>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63900>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63780>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63ac0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 42.347853 seconds =
(End Date) 2023-06-04 23:35:49 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d637e0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 79.904602 seconds =
(End Date) 2023-06-04 23:36:27 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63e80>
(Start Date) 2023-06-04 23:35:54 +0000 +
(Duration) 32.615227 seconds =
(End Date) 2023-06-04 23:36:27 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b480>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 48.341583 seconds =
(End Date) 2023-06-04 23:39:26 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d680a0>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 96.482671 seconds =
(End Date) 2023-06-04 23:40:14 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d69160>
(Start Date) 2023-06-04 23:39:34 +0000 +
(Duration) 40.684590 seconds =
(End Date) 2023-06-04 23:40:14 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6a240>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6a8e0>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6ba60>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b940>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b880>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000 {
HKSwimmingStrokeStyle = 5;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b6c0>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000])
HKWorkout
수영앱을 만들면서 데이터를 쿼리한 결과를 가공하기 위한 데이터 분석
우선 지금까지 수영 기록중에서 가장 최근 데이터를 뽑아서 Rawdata를 분석해보았다.
// record는 [HKWorkout]타입
print("-------------------------------")
print("SWIM! Swimming Data를 가져왔습니다. \\(records)")
print("-------------------------------")
print("SWIM DEBUG duration: \\(records[0].duration)")
if #available(iOS 16.0, *) {
print("SWIM! allStatistics: \\(records[0].allStatistics)")
print("SWIM! workoutActivities: \\(records[0].workoutActivities)")
}
print("SWIM DEBUG workoutActivityType: \\(records[0].workoutActivityType)")
print("SWIM DEBUG workoutEvents: \\(records[0].workoutEvents)")
HKWorkout.duration
duration | Apple Developer Documentation
duration: 총 운동 시간을 나타냄 (단위: Second)
duration: 3254.731590986252 // 약 54분
HKWorkout.allStatistics
allStatistics | Apple Developer Documentation
var allStatistics: [HKQuantityType : HKStatistics] { get }
데이터를 Dictionary형태로 나타냄. iOS 16이상.
수영 데이터에서는 RawData를 보아서는 수영거리, 스트로크 횟수, 휴식에너지, 활동에너지를 확인 할 수 있음.
아래 네가지 데이터타입을 받아서 사용하면 될 것으로 판단 됨.
HKQuantityTypeIdentifierDistanceSwimming
HKQuantityTypeIdentifierSwimmingStrokeCount
HKQuantityTypeIdentifierBasalEnergyBurned
HKQuantityTypeIdentifierActiveEnergyBurned
allStatistics:
[HKQuantityTypeIdentifierDistanceSwimming:
<<HKStatistics: 0x2816f0820>
Statistics on HKQuantityTypeIdentifierDistanceSwimming
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierSwimmingStrokeCount: <<HKStatistics: 0x2816f08f0>
Statistics on HKQuantityTypeIdentifierSwimmingStrokeCount
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierBasalEnergyBurned: <<HKStatistics: 0x2816f0a90>
Statistics on HKQuantityTypeIdentifierBasalEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierActiveEnergyB
urned: <<HKStatistics: 0x2816f0b60>
Statistics on HKQuantityTypeIdentifierActiveEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>]
HKWorkout.workoutActivities
HKWorkoutActivity는 운동 데이터별로 다양한 정보를 제공함.
workoutActivities | Apple Developer Documentation
workoutActivities:
[<HKWorkoutActivity 9B9EF1D0-42FD-4B5E-92F8-1D505D5CE5EC
<HKWorkoutConfiguration:0x2809d54a0
activity:HKWorkoutActivityTypeSwimming
location:outdoors swimming
location:pool
lap length:25 m>
2023-06-04 23:05:59 +0000 2023-06-05 00:00:14 +0000>]
HKWorkout.workoutActivityType
workoutActivityType: HKWorkoutActivityType(rawValue: 46)
HKWorkout.workoutEvents
workoutEvents | Apple Developer Documentation
운동시작 종료, 재개 등의 이벤트 데이터.
수영 앱에서는 랩타임, 휴식시간, 수영 스타일 등으로 활용 가능.
workoutEvents: Optional(
[HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62080>
(Start Date) 2023-06-04 23:06:00 +0000 +
(Duration) 621.031649 seconds =
(End Date) 2023-06-04 23:16:21 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62540>
(Start Date) 2023-06-04 23:16:03 +0000 +
(Duration) 18.785561 seconds =
(End Date) 2023-06-04 23:16:21 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeLap,
<_NSConcreteDateInterval: 0x282d625a0>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62620>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62660>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62600>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d626e0>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 14.534096 seconds =
(End Date) 2023-06-04 23:20:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62740>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 38.461768 seconds =
(End Date) 2023-06-04 23:20:28 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62780>
(Start Date) 2023-06-04 23:20:10 +0000 +
(Duration) 18.203081 seconds =
(End Date) 2023-06-04 23:20:28 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d629a0>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 41.486095 seconds =
(End Date) 2023-06-04 23:22:20 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62b20>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 53.803628 seconds =
(End Date) 2023-06-04 23:22:33 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62b80>
(Start Date) 2023-06-04 23:22:21 +0000 +
(Duration) 11.276112 seconds =
(End Date) 2023-06-04 23:22:33 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62c00>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62c60>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63300>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 15.085003 seconds =
(End Date) 2023-06-04 23:25:23 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63340>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 72.507750 seconds =
(End Date) 2023-06-04 23:26:21 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d633a0>
(Start Date) 2023-06-04 23:25:32 +0000 +
(Duration) 48.531872 seconds =
(End Date) 2023-06-04 23:26:21 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63460>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63520>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d634c0>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63580>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63680>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d633e0>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63740>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63880>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63900>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63780>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63ac0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 42.347853 seconds =
(End Date) 2023-06-04 23:35:49 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d637e0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 79.904602 seconds =
(End Date) 2023-06-04 23:36:27 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63e80>
(Start Date) 2023-06-04 23:35:54 +0000 +
(Duration) 32.615227 seconds =
(End Date) 2023-06-04 23:36:27 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b480>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 48.341583 seconds =
(End Date) 2023-06-04 23:39:26 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d680a0>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 96.482671 seconds =
(End Date) 2023-06-04 23:40:14 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d69160>
(Start Date) 2023-06-04 23:39:34 +0000 +
(Duration) 40.684590 seconds =
(End Date) 2023-06-04 23:40:14 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6a240>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6a8e0>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6ba60>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b940>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b880>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000 {
HKSwimmingStrokeStyle = 5;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b6c0>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000])
HKWorkout
수영앱을 만들면서 데이터를 쿼리한 결과를 가공하기 위한 데이터 분석
우선 지금까지 수영 기록중에서 가장 최근 데이터를 뽑아서 Rawdata를 분석해보았다.
// record는 [HKWorkout]타입
print("-------------------------------")
print("SWIM! Swimming Data를 가져왔습니다. \\(records)")
print("-------------------------------")
print("SWIM DEBUG duration: \\(records[0].duration)")
if #available(iOS 16.0, *) {
print("SWIM! allStatistics: \\(records[0].allStatistics)")
print("SWIM! workoutActivities: \\(records[0].workoutActivities)")
}
print("SWIM DEBUG workoutActivityType: \\(records[0].workoutActivityType)")
print("SWIM DEBUG workoutEvents: \\(records[0].workoutEvents)")
HKWorkout.duration
duration | Apple Developer Documentation
duration: 총 운동 시간을 나타냄 (단위: Second)
duration: 3254.731590986252 // 약 54분
HKWorkout.allStatistics
allStatistics | Apple Developer Documentation
var allStatistics: [HKQuantityType : HKStatistics] { get }
데이터를 Dictionary형태로 나타냄. iOS 16이상.
수영 데이터에서는 RawData를 보아서는 수영거리, 스트로크 횟수, 휴식에너지, 활동에너지를 확인 할 수 있음.
아래 네가지 데이터타입을 받아서 사용하면 될 것으로 판단 됨.
HKQuantityTypeIdentifierDistanceSwimming
HKQuantityTypeIdentifierSwimmingStrokeCount
HKQuantityTypeIdentifierBasalEnergyBurned
HKQuantityTypeIdentifierActiveEnergyBurned
allStatistics:
[HKQuantityTypeIdentifierDistanceSwimming:
<<HKStatistics: 0x2816f0820>
Statistics on HKQuantityTypeIdentifierDistanceSwimming
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierSwimmingStrokeCount: <<HKStatistics: 0x2816f08f0>
Statistics on HKQuantityTypeIdentifierSwimmingStrokeCount
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierBasalEnergyBurned: <<HKStatistics: 0x2816f0a90>
Statistics on HKQuantityTypeIdentifierBasalEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierActiveEnergyB
urned: <<HKStatistics: 0x2816f0b60>
Statistics on HKQuantityTypeIdentifierActiveEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>]
HKWorkout.workoutActivities
HKWorkoutActivity는 운동 데이터별로 다양한 정보를 제공함.
workoutActivities | Apple Developer Documentation
workoutActivities:
[<HKWorkoutActivity 9B9EF1D0-42FD-4B5E-92F8-1D505D5CE5EC
<HKWorkoutConfiguration:0x2809d54a0
activity:HKWorkoutActivityTypeSwimming
location:outdoors swimming
location:pool
lap length:25 m>
2023-06-04 23:05:59 +0000 2023-06-05 00:00:14 +0000>]
HKWorkout.workoutActivityType
workoutActivityType: HKWorkoutActivityType(rawValue: 46)
HKWorkout.workoutEvents
workoutEvents | Apple Developer Documentation
운동시작 종료, 재개 등의 이벤트 데이터.
수영 앱에서는 랩타임, 휴식시간, 수영 스타일 등으로 활용 가능.
workoutEvents: Optional(
[HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62080>
(Start Date) 2023-06-04 23:06:00 +0000 +
(Duration) 621.031649 seconds =
(End Date) 2023-06-04 23:16:21 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62540>
(Start Date) 2023-06-04 23:16:03 +0000 +
(Duration) 18.785561 seconds =
(End Date) 2023-06-04 23:16:21 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeLap,
<_NSConcreteDateInterval: 0x282d625a0>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62620>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62660>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62600>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d626e0>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 14.534096 seconds =
(End Date) 2023-06-04 23:20:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62740>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 38.461768 seconds =
(End Date) 2023-06-04 23:20:28 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62780>
(Start Date) 2023-06-04 23:20:10 +0000 +
(Duration) 18.203081 seconds =
(End Date) 2023-06-04 23:20:28 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d629a0>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 41.486095 seconds =
(End Date) 2023-06-04 23:22:20 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62b20>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 53.803628 seconds =
(End Date) 2023-06-04 23:22:33 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62b80>
(Start Date) 2023-06-04 23:22:21 +0000 +
(Duration) 11.276112 seconds =
(End Date) 2023-06-04 23:22:33 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62c00>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62c60>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63300>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 15.085003 seconds =
(End Date) 2023-06-04 23:25:23 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63340>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 72.507750 seconds =
(End Date) 2023-06-04 23:26:21 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d633a0>
(Start Date) 2023-06-04 23:25:32 +0000 +
(Duration) 48.531872 seconds =
(End Date) 2023-06-04 23:26:21 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63460>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63520>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d634c0>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63580>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63680>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d633e0>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63740>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63880>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63900>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63780>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63ac0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 42.347853 seconds =
(End Date) 2023-06-04 23:35:49 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d637e0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 79.904602 seconds =
(End Date) 2023-06-04 23:36:27 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63e80>
(Start Date) 2023-06-04 23:35:54 +0000 +
(Duration) 32.615227 seconds =
(End Date) 2023-06-04 23:36:27 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b480>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 48.341583 seconds =
(End Date) 2023-06-04 23:39:26 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d680a0>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 96.482671 seconds =
(End Date) 2023-06-04 23:40:14 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d69160>
(Start Date) 2023-06-04 23:39:34 +0000 +
(Duration) 40.684590 seconds =
(End Date) 2023-06-04 23:40:14 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6a240>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6a8e0>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6ba60>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b940>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b880>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000 {
HKSwimmingStrokeStyle = 5;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b6c0>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000])
HKWorkout
수영앱을 만들면서 데이터를 쿼리한 결과를 가공하기 위한 데이터 분석
우선 지금까지 수영 기록중에서 가장 최근 데이터를 뽑아서 Rawdata를 분석해보았다.
// record는 [HKWorkout]타입
print("-------------------------------")
print("SWIM! Swimming Data를 가져왔습니다. \\(records)")
print("-------------------------------")
print("SWIM DEBUG duration: \\(records[0].duration)")
if #available(iOS 16.0, *) {
print("SWIM! allStatistics: \\(records[0].allStatistics)")
print("SWIM! workoutActivities: \\(records[0].workoutActivities)")
}
print("SWIM DEBUG workoutActivityType: \\(records[0].workoutActivityType)")
print("SWIM DEBUG workoutEvents: \\(records[0].workoutEvents)")
HKWorkout.duration
duration | Apple Developer Documentation
duration: 총 운동 시간을 나타냄 (단위: Second)
duration: 3254.731590986252 // 약 54분
HKWorkout.allStatistics
allStatistics | Apple Developer Documentation
var allStatistics: [HKQuantityType : HKStatistics] { get }
데이터를 Dictionary형태로 나타냄. iOS 16이상.
수영 데이터에서는 RawData를 보아서는 수영거리, 스트로크 횟수, 휴식에너지, 활동에너지를 확인 할 수 있음.
아래 네가지 데이터타입을 받아서 사용하면 될 것으로 판단 됨.
HKQuantityTypeIdentifierDistanceSwimming
HKQuantityTypeIdentifierSwimmingStrokeCount
HKQuantityTypeIdentifierBasalEnergyBurned
HKQuantityTypeIdentifierActiveEnergyBurned
allStatistics:
[HKQuantityTypeIdentifierDistanceSwimming:
<<HKStatistics: 0x2816f0820>
Statistics on HKQuantityTypeIdentifierDistanceSwimming
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierSwimmingStrokeCount: <<HKStatistics: 0x2816f08f0>
Statistics on HKQuantityTypeIdentifierSwimmingStrokeCount
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierBasalEnergyBurned: <<HKStatistics: 0x2816f0a90>
Statistics on HKQuantityTypeIdentifierBasalEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>,
HKQuantityTypeIdentifierActiveEnergyB
urned: <<HKStatistics: 0x2816f0b60>
Statistics on HKQuantityTypeIdentifierActiveEnergyBurned
(2023-06-04 23:05:59 +0000 - 2023-06-05 00:00:14 +0000) over sources ((null))>]
HKWorkout.workoutActivities
HKWorkoutActivity는 운동 데이터별로 다양한 정보를 제공함.
workoutActivities | Apple Developer Documentation
workoutActivities:
[<HKWorkoutActivity 9B9EF1D0-42FD-4B5E-92F8-1D505D5CE5EC
<HKWorkoutConfiguration:0x2809d54a0
activity:HKWorkoutActivityTypeSwimming
location:outdoors swimming
location:pool
lap length:25 m>
2023-06-04 23:05:59 +0000 2023-06-05 00:00:14 +0000>]
HKWorkout.workoutActivityType
workoutActivityType: HKWorkoutActivityType(rawValue: 46)
HKWorkout.workoutEvents
workoutEvents | Apple Developer Documentation
운동시작 종료, 재개 등의 이벤트 데이터.
수영 앱에서는 랩타임, 휴식시간, 수영 스타일 등으로 활용 가능.
workoutEvents: Optional(
[HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62080>
(Start Date) 2023-06-04 23:06:00 +0000 +
(Duration) 621.031649 seconds =
(End Date) 2023-06-04 23:16:21 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62540>
(Start Date) 2023-06-04 23:16:03 +0000 +
(Duration) 18.785561 seconds =
(End Date) 2023-06-04 23:16:21 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeLap,
<_NSConcreteDateInterval: 0x282d625a0>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment,
<_NSConcreteDateInterval: 0x282d62620>
(Start Date) 2023-06-04 23:17:33 +0000 +
(Duration) 31.524181 seconds =
(End Date) 2023-06-04 23:18:04 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62660>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62600>
(Start Date) 2023-06-04 23:18:25 +0000 +
(Duration) 38.169073 seconds =
(End Date) 2023-06-04 23:19:03 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d626e0>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 14.534096 seconds =
(End Date) 2023-06-04 23:20:04 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62740>
(Start Date) 2023-06-04 23:19:49 +0000 +
(Duration) 38.461768 seconds =
(End Date) 2023-06-04 23:20:28 +0000,
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62780>
(Start Date) 2023-06-04 23:20:10 +0000 +
(Duration) 18.203081 seconds =
(End Date) 2023-06-04 23:20:28 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d629a0>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 41.486095 seconds =
(End Date) 2023-06-04 23:22:20 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62b20>
(Start Date) 2023-06-04 23:21:39 +0000 +
(Duration) 53.803628 seconds =
(End Date) 2023-06-04 23:22:33 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62b80>
(Start Date) 2023-06-04 23:22:21 +0000 +
(Duration) 11.276112 seconds =
(End Date) 2023-06-04 23:22:33 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d62c00>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d62c60>
(Start Date) 2023-06-04 23:23:03 +0000 +
(Duration) 42.869146 seconds =
(End Date) 2023-06-04 23:23:46 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63300>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 15.085003 seconds =
(End Date) 2023-06-04 23:25:23 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63340>
(Start Date) 2023-06-04 23:25:08 +0000 +
(Duration) 72.507750 seconds =
(End Date) 2023-06-04 23:26:21 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d633a0>
(Start Date) 2023-06-04 23:25:32 +0000 +
(Duration) 48.531872 seconds =
(End Date) 2023-06-04 23:26:21 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63460>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63520>
(Start Date) 2023-06-04 23:27:01 +0000 +
(Duration) 34.289119 seconds =
(End Date) 2023-06-04 23:27:35 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d634c0>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63580>
(Start Date) 2023-06-04 23:28:59 +0000 +
(Duration) 34.930590 seconds =
(End Date) 2023-06-04 23:29:34 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63680>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d633e0>
(Start Date) 2023-06-04 23:30:20 +0000 +
(Duration) 33.727744 seconds =
(End Date) 2023-06-04 23:30:54 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63740>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000 {
HKSwimmingStrokeStyle = 3;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63880>
(Start Date) 2023-06-04 23:31:11 +0000 +
(Duration) 39.541191 seconds =
(End Date) 2023-06-04 23:31:51 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63900>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d63780>
(Start Date) 2023-06-04 23:32:30 +0000 +
(Duration) 48.882447 seconds =
(End Date) 2023-06-04 23:33:19 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63ac0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 42.347853 seconds =
(End Date) 2023-06-04 23:35:49 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d637e0>
(Start Date) 2023-06-04 23:35:07 +0000 +
(Duration) 79.904602 seconds =
(End Date) 2023-06-04 23:36:27 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d63e80>
(Start Date) 2023-06-04 23:35:54 +0000 +
(Duration) 32.615227 seconds =
(End Date) 2023-06-04 23:36:27 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b480>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 48.341583 seconds =
(End Date) 2023-06-04 23:39:26 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d680a0>
(Start Date) 2023-06-04 23:38:38 +0000 +
(Duration) 96.482671 seconds =
(End Date) 2023-06-04 23:40:14 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d69160>
(Start Date) 2023-06-04 23:39:34 +0000 +
(Duration) 40.684590 seconds =
(End Date) 2023-06-04 23:40:14 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6a240>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6a8e0>
(Start Date) 2023-06-04 23:44:10 +0000 +
(Duration) 30.540489 seconds =
(End Date) 2023-06-04 23:44:41 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6ba60>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000 {
HKSwimmingStrokeStyle = 2;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b940>
(Start Date) 2023-06-04 23:45:07 +0000 +
(Duration) 47.679912 seconds =
(End Date) 2023-06-04 23:45:55 +0000, HKWorkoutEventTypeLap, <_NSConcreteDateInterval: 0x282d6b880>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000 {
HKSwimmingStrokeStyle = 5;
},
HKWorkoutEventTypeSegment, <_NSConcreteDateInterval: 0x282d6b6c0>
(Start Date) 2023-06-04 23:58:33 +0000 +
(Duration) 27.018217 seconds =
(End Date) 2023-06-04 23:59:00 +0000])
'개발 > Swift' 카테고리의 다른 글
SwiftUI에서 Figma 그림자 Blur, Spread 반영에 대한 고찰 (0) | 2023.05.24 |
---|---|
Swift at, in, to, with, from, by 등 전치사 쉽게 이해하기 (0) | 2023.05.12 |
macOS 파일 hash값 확인하기 (0) | 2023.05.12 |
@StateObject @ObservedObject @EnvironmentObject의 차이와 올바른 사용방법 (0) | 2023.05.06 |
WebSocket에 대한 간단한 개요 (0) | 2023.04.27 |