The Power of ChatGPT

For a SwiftUI project, I wanted to create a reusable package with all kind of (view)modifiers. A mundane task that ChatGPT can manage with ease.

Consider the code below to give a label a nice background with rounded corners. This works perfectly inside a standalone project. But it requires refactoring to convert it into a reusable package:

  • Mark the struct as public so that it can be accessed from outside the package.
  • Make the properties public if they need to be accessed from outside the package.
  • Provide a public initialiser to allow users of the package to initialise the BackgroundLabelStyle.


Label modifier usable for standalone execution

So, by just pasting this Swift source code into ChatGPT and asking "optimize for SwiftUI package", you get your desired code refactoring.


Label modifier converted by ChatGPT to be used in a reusable package

Da power of ChatGPT!



要查看或添加评论,请登录

社区洞察

其他会员也浏览了