UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Executing code while writing a package?

Forums > Swift

I have a swift package that I’ve created to block out some complex app logic (No UI in this case). Within the package I’ve embedded a Playground so that I can quickly execute the code against test data without having to import it into a project.

Unfortunately, playgrounds don’t show OSLog output on the console so my code is littered with print() commands. I’d like to update to OSLog so I can better test on devices, but I don’t want to lose the ability to quickly iterate in Xcode without the overhead of importing each package change into a project.

Any tips? What am I missing?

3      

Hi @Msans One possible solution could be to use conditional compilation directives in your Swift package. By conditionally including or excluding the OSLog statements based on the compilation target, you can maintain the ability to quickly iterate in Xcode with print() statements while still having OSLog statements for testing on devices. This way, you can have the best of both worlds without losing any functionality or convenience.

3      

Thanks @Miguelblanton . That seems like a good way to handle it.

3      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.