How to save typed object in CloudKit?

I am having trouble converting an object of type Data to a CNGroup object. I do ok until I save the Data in CloudKit and then retrieve it before I use my code to convert the Data to CNGroup. I believe I’m doing everything correctly. I am sure that I need to use the Data structure or NSData class in order to save an object in CloudKit, and that the filed should be of type bytes. Anyone have any pointers for me? I have used so much code that I can’t put it all here. I used the Data copyBytes and withUnsafeBytes methods, and the CNGroup object always comes from the pointee property of a typed unsafe pointer. That’s what all my code have in common.