GeometryReader in SwiftUI is a container view that provides access to its size and position within the parent view. Although you won’t always need to use it, it’s available when you’d like to know more about the views you’re working with. This is for you if you need to work more precisely, particularly with different screen sizes.
[Read more…]How to Use Swift Charts with SwiftUI in Your iPhone App
Many apps use charts to represent data to the user. This is especially so for apps such as weight tracking, step counting, and anything else that is HealthKit related. Thankfully, Apple has created the Swift Charts framework to help you build these charts.
In today’s tutorial, we’ll look at extracting step count data from HealthKit and representing that in a chart within a SwiftUI application. We will have two charts, the first being a bar chart showing today’s step counts broken into hours and the second showing daily step counts for the last thirty days.
This tutorial will cover fetching information from HealthKit, processing that data and formatting it to make it easier to pass values to the charts framework. It will cover creating the views and the prompt needed to grant the necessary permissions.
[Read more…]Building a SwiftUI Note-Taking App with ChatGPT Integration for iPhone – Tutorial
In a recent tutorial, I took you through the basics of creating a chat app where you could ask a question and then receive an answer using the ChatGPT from OpenAI. That tutorial covered basic HTTP post requests and responses and included the structs that allowed a request to be encoded and a response to be decoded. It also had a simple view that allowed you to enter your API key from OpenAI and a TextField to ask a question.
In this tutorial, we will take this in the direction of a note-taking app for meetings with ChatGPT integration. The app will allow you to take notes and then have ChatGPT to do several things, such as extract action points, summarise lengthy notes, extract dates and times and put them into a bullet list. With AI, there are many options. I’ve only touched on a tiny amount of them here.
[Read more…]Integrating DALL-E to Generate Images in Your SwiftUI iPhone App
In the last tutorial, we looked at ChatGPT chat conversations and added a simple user interface to a SwiftUI app. Today we will look at integrating DALL-E into your SwiftUI app, using the image generations endpoint that allows you to provide a prompt and generate one to ten images. The app will be similar to what was created yesterday. The difference is that instead of receiving an answer in text form, we’ll receive it as a URL that can then be processed to display on the view.
[Read more…]ChatGPT Integration: Building a SwiftUI Chatbot for Your iPhone App
In the past year, ChatGPT has brought AI to the limelight. ChatGPT 3 was the model in use when I first heard of it last year. Just like it did with me, It has captured the interest of many people and businesses.
ChatGPT can be used for many things, such as finding answers to daily questions, solving maths problems, writing blog posts, and writing code, to name a few.
In this tutorial, we’ll connect a SwiftUI app to OpenAI’s ChatGPT API to provide a chatbot for your mobile app. The tutorial will briefly cover how to create a simple user interface and connect to OpenAI’s API to receive answers to questions you ask within the app.
The application here is just a chatbot, but you can use what you learn here to add value to any kind of app such as a note-taking app where a user can write some notes and then use AI to either add, summarise or correct what has been written.
OpenAI’s API is very similar to many other APIs on the internet in that you create an HTTP request, such as a POST request, add the bearer to the header, add items to the body, and then post it. The API then passes back a result that contains the answer you need.
[Read more…]How to add a Map to a SwiftUI App
Many iPhone apps use maps to display helpful information to the user, often showing the current location. Uses include maps for navigation, finding nearby places, adding location to notes, reminders, and so on. This short tutorial will teach us two ways to add a map to an app.
Using MapKit
The MapKit framework makes adding a map to your app simple. You can first begin by importing MapKit into your view as follows:
import MapKit
How to Use Local Notifications
There are two categories of notifications on iOS devices. One type is a push notification sent by a server, and the other is a local notification scheduled on-device that appears at a particular time or location.
This tutorial focuses on local notifications. An example of a local notification can be seen in your calendar. You add an appointment, set it to remind you 15 minutes before, and 15 minutes before the meeting begins, you see a notification on your lock screen. Let’s take a look at how these work.
[Read more…]The SwiftUI App Life Cycle
When Xcode 12 was launched in 2020 it brought with it a new app life cycle for SwiftUI applications. Prior to this, SwiftUI based apps were using AppDelegate.swift and SceneDelegate.swift.
Creating a new app can be done with this code:
import SwiftUI
@main
struct MyNewApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Apple Sample Code for Three-Column Layout in SwiftUI
For the last few weeks, I have been making plans for a new iPad/iPhone, and potentially macOS application. I haven’t used SwiftUI much in development so wasn’t sure how best to sort out the navigation on both mobile devices.
The app I am building, which is in very early stages, is for note-taking and meeting planning. My plan was to use a two-column layout, much like master/detail, but it seems that one good option is the three-column layout that has a menu on the far left column, a list view in the centre column, and then details on the rest of the view, as seen below.
[Read more…]Unable to use SwiftUI Preview due to Insufficient System Resources
If you are getting an error saying that you cannot preview this file (while using SwiftUI), then perhaps like my experience, a reboot might fix it. That’s the short version to possibly get you going before reading on.
I created a new project today and switched the default ContentView.swift to use an iPad Pro 11 inch for the preview. An error appeared in right pane saying “Cannot preview in this file – Unable to boot device due to insufficient system resources”. Clicking the diagnostics button provided the following:
HumanReadableNSError: Unable to boot device due to insufficient system resources.
Please see Simulator Help for information on adjusting resource limits.
NSPOSIXErrorDomain (67):
==NSLocalizedFailureReason: The current system settings are not sufficient to allow booting additional simulators: maxFiles: 12288, openFiles: 11669, enforcedFilesBuffer: 1868
As mentioned, a reboot fixed the issue. It seems that Apple last recognised this happening back in 2017 in the Simulator Help section on the Apple help site that gives some recommendations on how to modify the number of processes and number of open files.
- 1
- 2
- 3
- …
- 7
- Next Page »