0

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.

denniswave
  • 127
  • 6
  • 1
    Scan something in a device and scan something, and save them into `UserDefaults`. Open the value from UserDefaults as `Data`, and print it (see https://stackoverflow.com/questions/39075043/how-to-convert-data-to-hex-string-in-swift ) print that content into Console, and copy that content. In your app, add an new file and paste that data into it. Then, you can read that data (from your bundle) to use it in your simulator. You can also "sent it" by email/airdrop" instead of using console, it depends on what you "can do", and what's easier/quicker for you. – Larme Nov 02 '22 at 09:54

1 Answers1

1

You are doing this:

  • RoomScan --(via NSKeyedArchiver/Encodable)--> Data --(save)--> UserDefaults
  • UserDefaults --(read)--> Data --(via NSUnarchiver/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.

Larme
  • 24,190
  • 6
  • 51
  • 81
  • Thanks! This worked for me: I intercepted some scans and converted the `Data` objects to Hex Strings. I just copied the stings from my console to a separate Swift file and converted them back to `Data` objects to use in my test apps using this extension: [Converting Hex String to NSData in Swift](https://stackoverflow.com/a/64351862/11102315). – denniswave Nov 03 '22 at 10:14