I'm saving the last n log messages in user defaults as a means of tracing crashes. The log data includes a string that has an interpolated call to a function that returns a formatted time string. When I retrieve it later after a cold start by the app, I'm seeing the current time displayed rather than the time the log entry was saved.
I've tried using String(format: "%@", "\(timeStamp())" before saving the string in an effort to get the time stamp, but I'm still seeing the time the message is retrieved. I break pointed the function formatting the time and it doesn't appear to get called, but all the log messages in the string array have the same current time that is minutes after the original message was logged.
Is this expected behavior? Is there a way to ensure I have a static string that will reflect the original string result?
I'm using xcode 13.2.1.