How to use ChatGPT to Write Code

Introduction

Welcome to an exciting exploration into the capabilities of ChatGPT. Join me as we push the boundaries of ChatGPT to generate SwiftUI code snippets. Will ChatGPT coding rise to the occasion and seamlessly weave together the intricate syntax of SwiftUI? Let's dive in and witness the fascinating interplay between human creativity and machine intelligence in the context of SwiftUI development.

Escaping the Tutorial Hell

If you want to escape tutorial hell, go ahead and book a call with me at rebeloper.com/mentoring. Today, we are going to ask ChatGPT to build us some sort of an application to help us with some code. Along the way we will find out is ChatGPT for coding. I have just started a brand new Xcode project. Let's take a look at some ChatGPT coding examples.

Giving Prompts to ChatGPT

Now we are going to give some prompts over here and let's see what ChatGPT 3.5 will give us. I'm going on the free version. Let's see how far we can go before we can break ChatGPT in this. Usually, as a word of advice, I heard that one should not ask ChatGPT to just build a whole application. So we are going to test that. Let's see if we just ask some basic apps if it can build it out.

ChatGPT as a SwiftUI Senior Developer

First of all, let's just open up a new chat and what I want to say to ChatGPT is that it is a SwiftUI senior developer. We want to say that this is you and this is your expertise. It knows from where to get all of its information and what it needs to do. So I will give it some prompts, some ideas, some questions, and it needs to spit out some SwiftUI code. This is my end goal. So let's see.

ChatGPT prompt to settle the User to be a SwiftUI expert

Building a Countdown Timer Application

We start off with a countdown timer application. Let's see if it knows that it's in SwiftUI.

ChatGPT countdown timer prompt

We'll use a date picker. Let's see how this will look like. The code defined a simple SwiftUI view with a date picker to set the target time and two text views to display the remaining time. The start countdown function uses a timer to update the remaining time every second and the formatted time function formats the remaining time in hours, minutes, and seconds. You are free to customize this code according to your requirements.

Debugging the Code

Let's see if this code is actually valid. Let's jump into Xcode and paste it in there. We can can easily see that thios code is not valid.

Overcoming Challenges

We want to have @State private timer equals a timer. Let's feed ChatGPT much smaller tasks.

ChatGPT prompt

The code thta ChatGPT puts out now is much better. You can also customize the given code.

ChatGPT prompt to customize SwiftUI code

This is the final code that ChatGPT gave us. Nice!

Conclusion

Is ChatGPT alternative for coding? In conclusion, when you are coding with ChatGPT, think of it like an assistant. You don't want the assistant to be overwhelmed. You should take it one step at a time and then improve maybe have some bug fixes and it can handle it really, really nicely. Also if you don't understand some code just give it and make sure that you always specify that it is an expert in that field.

Improve Your iOS Development Skills

Embark on a personalized journey to elevate your iOS development skills with my exclusive mentoring sessions at rebeloper.com/mentoring. As an experienced iOS Developer, I offer one-on-one guidance to help you tackle your coding challenges and refine your app development expertise. Take the first step toward unlocking your full potential as an iOS Developer.