Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use strings for OSLogMessage?

Tags:

swift

Given the following two lines, XCode is showing an error for the second line saying Cannot convert value of type 'String' to expected argument type 'OSLogMessage'.

logger.info("Device found:")
logger.info(String(describing: device))

Can someone please explain why this error is shown? In both cases, the parameter is of type String. (I guess)

Currently, I fix this by using string interpolation. But this does not feel right. Is there a better way than:

logger.info("\(String(describing: device))")
like image 817
Stephan Avatar asked Dec 05 '25 01:12

Stephan


1 Answers

The (surprising, perhaps) answer is that OSLog doesn't allow an arbitrary string to be logged for privacy reasons. It's not a language limitation but a policy to control the availability of user data in logs.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!