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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.