GO FURTHER, FASTER: Try the Swift Career Accelerator today! >>

How do I prepare CloudKit data for Swift Charts?

Forums > Swift

I have created a simple app where a user is tracking their mood. A simple click of the button inserts the necessary data to a CloudKit database. So I consider each record as a 'transactional' record.

I am able to successfully query the data and present in a list view. I am able to sort and incorporate simple predicates. I am now at a point in my development that I would like to add a pie chart based on the users data and I am not sure how to roll-up the data / group by the data / aggregate the data (I am not sure what the correct terminology is within Swift)

The pie chart would show the various moods that the exists in the CloudKit database and the slices would be sized based on the count of each mood.

Any guidance that you can provide would be greatly helpful!

https://share.icloud.com/photos/080IWo4ljrq69lkFKslNIuq7w

1      

My solution for now is to create a second table that holds the mood value and the count.

When a user tracks their mood, I will make 1 insert into the transactional/detail record type and then update the count in the 1 record in the second table.

The pie chart is sourced from the new table and the list view displays data from the transactional table

This seems to work for me.

If anyone has a better way to do this, I am open to hear.

1      

Hacking with Swift is sponsored by try! Swift Tokyo.

SPONSORED Ready to dive into the world of Swift? try! Swift Tokyo is the premier iOS developer conference will be happened in April 9th-11th, where you can learn from industry experts, connect with fellow developers, and explore the latest in Swift and iOS development. Don’t miss out on this opportunity to level up your skills and be part of the Swift community!

Get your ticket here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.