I'm working on a RoomPlan app. I've successfully managed to capture, save and load scans using NSKeyedArchiver. However, for apps run on the simulator or on devices without a LiDAR Scanner, I do not have any scans saved on that device so I cannot test the functionality. I want to "fill" my app with a test scan or two to be able to test my app on those devices.
The core problem here is that I can't figure out how to "capture" objects in Swift and save them hardcoded in the app instead of in NSKeyedArchiver, which is local to every device.
CodePudding user response:
You are doing this:
RoomScan
--(viaNSKeyedArchiver
/Encodable
)-->Data
--(save)-->UserDefaults
UserDefaults
--(read)-->Data
--(viaNSUnarchiver
/Decodable
)-->RoomScan
So, what I suggest:
Scan a room, then convert it as Data
, save it if needed.
Intercept that Data
either by forcing a reading, or before saving into UserDefaults
.
Choose the solution you find easier/quicker for you for the "intercept":
Convert the Data
into HexString (see How to convert Data to hex string in swift), print it into Console, copy the output or save maybe that content into a Data file, and send it via AirDrop/Mail.
Create a new file into your project, and read it when needed (simulator, etc). Depending on the solution chosen since the writing might differ, the reading also might differ.