The genie's out of the bottle and there's no turning back! If you haven't tried AI-assisted programming yet, now is a great time to dive in. Tools such as ChatGPT have come a long way from their inception. You'll be amazed at how much more productive you'll be and wonder how you ever managed without them.

In this article, I explore practical applications of ChatGPT for iOS app development, debunk common myths, and showcase its potential and pitfalls as a coding partner. Whether you're new to ChatGPT or already familiar with it, you'll find valuable information about recently released features, including Projects and Canvas Mode. This article specifically highlights the capabilities of ChatGPT Plus and GPT-4 Turbo, unlocking new levels of efficiency and creativity.

ChatGPT: Fear and Loathing

I've encountered some negative reactions when discussing AI-assisted programming with some developers. This resistance is a common response to disruptive technologies. One argument I often hear is “A developer worth their salt doesn't need ChatGPT.” I believe this sentiment stems in part from the negative publicity ChatGPT received early on, including stories of students using it to write essays, complete assignments, and pass exams, passing off the AI-generated work as their own. As a result, some developers equate using ChatGPT with cheating or, worse, as an admission of inadequacy and incompetence.

In response, I make the point that ChatGPT is just another tool in a developer's arsenal. It helps you perform your usual tasks faster and more accurately. Not using ChatGPT is like refusing to upgrade to a newer compiler that's better at finding coding errors—it's a missed opportunity to enhance your productivity and code quality. Just as an improved compiler can catch subtle bugs, suggest optimizations, or provide clearer error messages, ChatGPT serves as a coding assistant that improves your efficiency. It can help debug tricky issues, generate boiler plate code, or even clarify complex programming concepts, giving you more time to focus on solving challenging problems.

Then there's the fear that AI will make coders obsolete. I talked to one aspiring programmer who decided not to pursue a career in coding believing that tools like ChatGPT would handle all coding tasks, leaving little need for human input. I think this speaks to a lack of awareness of AI's limitations. AI is far from replacing the creative, human-centric aspects of development. Programming often involves deeply understanding business needs, solving ambiguous problems, and crafting creative and efficient solutions—areas where human developers excel. ChatGPT enhances efficiency and creativity, but doesn't replace critical thinking or domain expertise.

ChatGPT enhances efficiency and creativity, but doesn't replace critical thinking or domain expertise.

Ultimately, ChatGPT doesn't “think” or innovate; it assists with repetitive or time-consuming tasks, leaving humans to focus on innovation and strategy. Understanding what AI encompasses helps contextualize its role. Artificial intelligence refers to systems or machines that simulate human intelligence to perform tasks. AI can be categorized into:

  • Narrow AI (Weak AI): Focused on specific tasks, such as language processing, or image recognition. ChatGPT falls into this category.
  • General AI (Strong AI): A hypothetical future system capable of performing any intellectual task a human can do, including reasoning and self-awareness.

ChatGPT is Narrow AI, specializing in generating and understanding natural language rather than possessing human-like intelligence.

Throughout this article and in those to come, I'll highlight the limitations and strengths of using AI as a tool. Ultimately, ChatGPT isn't coming for your job, but people who know how to leverage it are.

ChatGPT isn't coming for your job, but developers who know how to leverage it are.

ChatGPT Free vs. Paid Version

Although there's a free version of ChatGPT available, I highly recommend subscribing to ChatGPT Plus for $20 per month. The free version (GPT-3.5) has decent capabilities, but the tools you really need are in GPT-4 Turbo with ChatGPT Plus.

Here are the extras you get with ChatGPT Plus that you don't get with the free version, which I outline in more detail in the next section:

  • Projects: Organizes and manages work by creating persistent, structured spaces for related tasks, documents, and code. It's ideal for long-term project like app development.
  • Coding Assistance: It possesses far more comprehensive understanding and debugging of complex code, refactoring large codebases, and designing intricate software patterns.
  • Larger Context Window: The free version of ChatGPT can only handle shorter snippets of code (approximately 4,096 tokens or pieces of text). In contrast, ChatGPT-4 Turbo processes 128,000 tokens, handling longer code files and project discussions.
  • Image Inputs: Analyzes and responds to questions about uploaded images.
  • Document Analysis: Reviews and extracts information from uploaded documents.
  • Advanced Coding Assistance: Has enhanced reasoning capabilities for complex coding tasks and debugging.
  • DALL-E Image Generation: Creates and edits images directly in the chat, including editing specific parts of an image.
  • Canvas Mode: Provides a dedicated workspace for editing long-form content or working on code collaboratively.

Given the obvious advantages over the free version, this article focuses on ChatGPT-4 Turbo. Let's take a closer look at some of these features and how they can enhance your app development.

Working with the Projects Feature

Projects, introduced on December 13, 2024 during OpenAI's 12 Days of OpenAI event, provide a structured workspace for managing long-term or multi-step tasks. Projects lets you keep related work organized, including files and datasets, as well as group multiple conversations-related topics. ChatGPT Plus users can create an unlimited number of projects.

In Figure 1, you can see a list of projects in the left panel of the ChatGPT Desktop window.

Figure 1: ChatGPT lists the projects you create in its left-hand side bar.
Figure 1: ChatGPT lists the projects you create in its left-hand side bar.

I've created projects for:

  • My book, Coding iOS Apps with ChatGPT
  • A training seminar I'm giving in Germany
  • This series of CODE Magazine articles

These folders allow me to keep the different projects I'm working on organized. When I switch tasks during my workday, I just click the project I want to work on and begin interacting with ChatGPT.

Let's create a new project to see how this works.

  1. Hover your mouse over Projects in the sidebar and click the plus (+) button that appears. This displays a New Project dialog, as shown in Figure 2.
  2. Enter the name of the project (for example, ChatGPT Demo Project).
  3. Click the Create project button.
Figure 2: ChatGPT Plus-tier users can create an unlimited number of projects.
Figure 2: ChatGPT Plus-tier users can create an unlimited number of projects.

This displays your new project in the Project Panel on the right (Figure 3). At the top-left of the Project Panel is a folder. If you hover your mouse over this folder, a pencil icon appears that, when clicked, allows you to set the color of the project folder in the side panel. You can also hover over the project name, click the pencil icon that appears and change the name of the project.

Figure 3: Creating or selecting a project displays the Project Panel on the right.
Figure 3: Creating or selecting a project displays the Project Panel on the right.

Adding Project Instructions

You can tailor ChatGPT's responses within a project by adding instructions. For example:

  • Follow Swift API Design Guidelines, using camelCase for variables and PascalCase for classes and structs.
  • The app must support iOS 17 and later.
  • Use SwiftUI for building the user interface, with reusable components.
  • Use Alamofire for networking.
  • Use ObservableObject for state management.
  • Ensure offline caching is implemented using CoreData.

After specifying instructions, ChatGPT actively uses them as a reference when answering project-specific questions. Let's try out this feature.

  1. In the Project panel, click the Add Instructions button.
  2. In the Instructions dialog (Figure 4), enter When answering questions about the JSON files in this project, display responses in YAML format unless specified otherwise.
  3. Click Save to add this instruction to the project. This displays the first several words of the instruction in the Instructions UI control.
Figure 4: Add instructions to tailor the way ChatGPT responds to questions in your project.
Figure 4: Add instructions to tailor the way ChatGPT responds to questions in your project.

In the next section, you'll add a JSON file for ChatGPT to analyze and process so you can see this instruction at work.

You can tailor ChatGPT's responses within a project by adding instructions.

Adding Project Documents and Files

In October 2023, OpenAI expanded ChatGPT's ability to interpret and respond to visual inputs such as diagrams, screenshots, and handwritten notes—features I use every day. For example, I can take screenshots of several pages of mobile app exceptions logged in Sentry.io and ask ChatGPT for insights, like “What percentage of errors are being caused by nullable exceptions?” ChatGPT's answers help me get the big picture of where I should concentrate my efforts. Similarly, I can upload a screenshot of an Xcode Instruments Performance Report to identify high memory usage or excessive CPU consumption and get optimization recommendations.

ChatGPT excels at processing uploaded documents, such as PDFs and Word documents, offering capabilities for extracting, summarizing, and analyzing data. For example, although ChatGPT didn't write my latest book, I uploaded the draft Word document and asked it to check for spelling and grammatical errors. Its multi-lingual abilities are also impressive; I recently received PDF documents in German from two hotels for a seminar I'm holding in Germany. I uploaded both documents and asked ChatGPT to give me an overview of each contract to help me decide on the venue. It did a great job of translating the documents into English and giving me a list of pros and cons for each hotel.

If you want to use this feature for your projects, the Add files option in ChatGPT's Projects panel is the best way to upload documents or datasets. Let's kick the tires on this feature. In the download files for this article (on www.codemag.com), there's a project_data.json file that contains a fictional dataset about projects, tasks, and team members.

Here are the steps to upload a file:

  1. In the Projects panel, click the Add files button to open the Project files dialog (Figure 5).
  2. Click the Add files button.
  3. Navigate to the folder that contains the project_data.json file, select it, and then click Open.
  4. An upload progress indicator appears. Once the upload is complete, an icon indicating the file type is displayed.
  5. Close the dialog by clicking the X in the top-right corner.

After uploading, the UI displays: Project files – 1 file.

Figure 5: You can upload documents and files associated with a project for ChatGPT to analyze.
Figure 5: You can upload documents and files associated with a project for ChatGPT to analyze.

With the file uploaded, you can query its contents. Try entering the following command in the Chat Input field: Summarize the projects in the project data JSON file, including their names, descriptions, and statuses.

Click the Send button (up arrow) in the bottom-right corner of the Chat Input Field to send the request.

ChatGPT responds by summarizing the projects in YAML format, as specified in the project instructions (Figure 6).

Figure 6: Analyze file contents by asking ChatGPT specific questions.
Figure 6: Analyze file contents by asking ChatGPT specific questions.

You can also try questions like:

  • Show me all team members and their roles.
  • Show me all tasks assigned to John Doe.
  • What projects haven't started yet?
  • Calculate the total duration of each project.

These features make ChatGPT a power tool for analyzing project data and extracting actionable insights from uploaded files.

Canvas Mode

Canvas Mode is one of ChatGPT's most powerful features, providing a dedicated workspace for editing long-form content or collaborating on code. This mode is especially useful for managing complex projects, providing developers with tools to organize and visualize their work.

Here are some of the key features of Canvas Mode:

  • Focused Editing: Canvas Mode allows you to view and edit your code or content in a distraction-free environment, which is ideal for managing extensive codebases or lengthy documentation.
  • Collaboration: If you have an enterprise version of ChatGPT, you can collaborate with team members by sharing the canvas workspace. Changes appear in real-time, making it easier to co-develop or review.
  • Version Tracking: Canvas Mode saves changes as iterations, making it easy to revert to previous versions. This feature is crucial for maintaining code integrity during iterative development.
  • Enhanced Visualization: With syntax highlighting, formatting options, and structured file organization, Canvas Mode makes it easy to navigate large projects.

To create a new canvas, type the following in the ChatGPT chat window: Create a blank canvas with a simple SwiftUI Hello World view in it.

When you do this, the ChatGPT sidebar disappears, the Chat window takes its place, and the canvas appears on the right side of the screen, as shown in Figure 7.

Figure 7: The new ChatGPT canvas provides a dedicated workspace for editing long-form content.
Figure 7: The new ChatGPT canvas provides a dedicated workspace for editing long-form content.

Now you can manually edit the code in the canvas or ask ChatGPT to make modifications. For example, you could type: Add a navigation bar to this view.

ChatGPT animates the code update, showing changes line by line as it works. The newly added NavigationView appears in the canvas, as shown in Figure 8.

Figure 8: ChatGPT animates code updates in a canvas.
Figure 8: ChatGPT animates code updates in a canvas.

At the bottom right corner of the canvas is an action menu. Hover over it to access several options (Figure 9).

  • Add Comments: Automatically inserts comments into your code in the canvas
  • Add Logs: Adds print() statements to your code to track key events in your app
  • Fix Bugs: Analyzes the code file line by line to detect and fix bugs
  • Port to a Language: Opens a popup to select a target language: PHP, C++, Python, JavaScript, TypeScript, Java. It then creates a new canvas with the converted code.
  • Code Review: Reviews the code line by line, adding comments with suggestions for improvement
Figure 9: The canvas action menu gives easy access to key features.
Figure 9: The canvas action menu gives easy access to key features.

For instance, selecting Add Comments and Add Logs results in automatically annotated code with well-placed log statements, as shown in Figure 10. Although the comments exceed what you normally write, the logging statements are well placed.

Figure 10: ChatGPT can automatically add comments and log statements to your code.
Figure 10: ChatGPT can automatically add comments and log statements to your code.

The Code Review is an interesting option—especially when ChatGPT reviews the code it generated itself. Figure 11 shows the result of this code review. As you can see, ChatGPT highlights specific lines of code and offers improvement suggestions in a balloon on the right. I've worked extensively with ChatGPT over the last few years in both Swift and C# code, and it's surprisingly good at finding issues with your code.

Figure 11: ChatGPT is surprisingly good at offering suggestions for improving your code.
Figure 11: ChatGPT is surprisingly good at offering suggestions for improving your code.

At the top-right corner of the canvas, version control buttons allow you to go navigate between iterations of your code or copy the current version to your clipboard. These tools ensure that you can easily track your work.

All in all, Canvas Mode allows ChatGPT to not just be a coding assistant, but a part of the development process. Whether you're editing, debugging, or porting code, the features in Canvas Model make it a great tool for developers.

Holding ChatGPT Accountable

For all of its virtues, there are times when ChatGPT can be very frustrating. It's perfectly capable of generating code that contains critical errors that prevent compilation. Fortunately, in most cases, it provides a corrected solution. However, there are times when resolving issues requires more persistence and context.

I was working on some low-level C# code today, and ChatGPT was stuck in a loop of producing code that wouldn't compile. To get around this, I located the relevant .NET class-level code file, copied it, and pasted it into the chat. With that additional context, ChatGPT finally produced code that worked without a hitch. I was curious, so I asked ChatGPT why it didn't know about the existence of the method I needed. It replied:

That's a great question! The reason I initially missed the method is that I don't have direct access to every library's source code or detailed documentation unless provided during our conversation. My suggestions are based on my training, publicly available knowledge, and the context you provide.

As another example, I was working on a simple Swift view and asked ChatGPT How do I set the background color of this view? I already knew the answer to this question, but was testing ChatGPT's knowledge. It suggested a somewhat overcomplicated approach using a ZStack. I suggested setting the background color directly on the view and ChatGPT agreed that was a better solution. However, when I pasted a different page into the chat box and asked the same question, it gave me the same overcomplicated solution. I then asked: Why do you keep recommending to use a ZStack when it's not a best practice?

ChatGPT responded as shown in Figure 12, thanking me for keeping it accountable! LOL.

Figure 12: ChatGPT may thank you for holding it accountable.
Figure 12: ChatGPT may thank you for holding it accountable.

Another common pitfall arises when asking ChatGPT to improve or upgrade a class. For example, I've uploaded code and requested general improvements or specific updates, like upgrading to the latest version of a NuGet package. About half the time, ChatGPT completely removes necessary methods from the class without explanation.

Just yesterday, it removed a dozen essential methods from a class. For each missing method, I asked if the omission was intentional and each time it replied as shown in Figure 13.

Figure 13: Beware of ChatGPT removing necessary code from your classes!
Figure 13: Beware of ChatGPT removing necessary code from your classes!

The takeaway here is this: You need a healthy measure of caution when accepting code, advice, or solutions from ChatGPT. You must understand the problem, the programming language, and the relevant libraries well enough to know when ChatGPT's suggestions are off-base. Maintaining a healthy level of skepticism ensures that you can effectively navigate its limitations.

You need a healthy measure of caution when accepting code, advice, or solutions from ChatGPT.

Brainstorming App Ideas

ChatGPT is a great resource for brainstorming app ideas. While writing this article, I asked ChatGPT the following question:

I'm writing a set of four articles for CODE Magazine that shows how to use ChatGPT as an AI assistant when building iOS apps. Give me five ideas for a sample app to include in these articles.

Here are the titles ChatGPT generated (it also provided detailed descriptions and features for each, but I've listed just the titles here):

  1. TaskFlow: A Collaborative Task Manager
  2. RecipeBuddy: A Smart Recipe Manager
  3. FitTrack: A Personal Fitness Tracker
  4. TravelMapper: A Trip Planning App
  5. MoodJournal: A Mental Health and Wellness App

I liked the TravelMapper idea. My wife and I recently took a trip to Ireland. Although we used ChatGPT to help us plan our itinerary, we did most of the work with pen and paper. It would have been great to have an app streamline the process. Here's the detailed app description ChatGPT gave us.

TravelMapper: A Trip Planning App

Concept: An app that allows users to plan trips, save destinations, and explore activities near their locations.

Features:

  • Add trip details like destination, dates, and activities.
  • Display trips on an interactive map using MapKit.
  • Show nearby attractions with real-time location updates.
  • Generate itineraries with suggested activities.
  • Save trip memories with a photo journal.

Why it's great:

  • Highlights ChatGPT's ability to assist with MapKit and location services.
  • Demonstrates real-time API integration for fetching local attractions and weather data.

Okay, I'm sold! This app idea was useful and shows the potential of using ChatGPT as a development assistant. However, before moving forward, I asked ChatGPT:

Is the name TravelMapper already associated with existing travel-related applications?

ChatGPT responded:

The name TravelMapper is already associated with existing travel-related applications (and it provided a list of these). Given the existing use of TravelMapper and similar names in the travel app domain, it's advisable to select a unique name to avoid potential trademark conflicts and ensure distinct branding.

ChatGPT then suggested a list of alternative names, from which I chose TripNavigator. So, TripNavigator it is! This will be the app we'll build together in the upcoming articles in this series. Stay tuned as we bring this idea to life with ChatGPT's help!

Conclusion

Integrating AI tools like ChatGPT into your iOS development workflow can be a game-changer, transforming how you approach coding challenges, streamline your processes, and even brainstorm creative ideas. By embracing its strengths while keeping a watchful eye on its limitations, you can make the most of its potential as a coding companion rather than as a replacement for your expertise. Although skepticism around AI assistance persists, the developers who adapt and leverage these tools effectively will be the ones shaping the future of development.