Day 7 : 14 June 2022 : iOS Part 2 - A SwiftUI Sample App
My 100 Daze of Code
https://github.com/davidjwalling/100-days-of-code
Day 7 : 14 June 2022 : iOS Part 2 - A SwiftUI Sample App
I am not a front-end developer. I have no business trying to create anything remotely resembling a UI. UX is dead to me. But, since I have set out to put project Ava on iOS, I do need something to look at. So here, we'll use Xcode on macOS to generate (I won't even say "program") the simplest out-of-the-box app that we can then use to hook into our C++ library.
I'm using macOS 12.4 Monterey with Xcode 13.4.1. The iOS device is an 11" 3rd-Generation iPad running iOS 15.5.
Create a Workspace
Launch Xcode. Select File|New|Workspace (or Control-Command-N). I'm naming the workspace "ava" and saving it in the repositories base folder (100-days-of-code).
If you save the workspace in the repository root like this, the workspace in Xcode automatically detects the Git configuration and can display the current branch and commit.
In Finder, you should see the "ava.xcworkspace" item nestled happily among the other repository files.
Create a Project
Now, we'll create a new project within the workspace. Use the File|New|Project menu item or enter Shift-Command-N to open the New Project dialog. Choose "iOS" and "App" and click Next.
Enter project options. Here, use the Product Name, Team, and Organization Identifier fields to generate the Bundle Identifier, which should exactly match the App ID created in your developer.apple.com account. We're using SwiftUI as the Interface and Swift as the Language. Click Next.
Select the repository base folder "100-days-of-code" as the location to store the project. Uncheck "Create Git Repository on my Mac" because there already is a Git repository there. Select the workspace ("ava" in this example) for "Add to" and "Group". Then click Create.
Now, if all goes well up to this point, a simple SwiftUI app is generated, built and the simulator is run. The sample program outputs a "Hello, world!" message to the simulated iPad.
Here, the workspace, group and app are all named "ava". This is logical for the project. However, let's look at the folder and file structure that this created inside our repository by looking again at Finder.
What we see is that an "ava" folder was created in the repository root folder. While this is okay, in the long term it might make more sense visually if this folder was named "ios" instead, since it holds artifacts that relate only to iOS builds. We will experiment with this further on a later day to see if this structure can be made more intuitive.
Debug the Program on an iPad
To confirm our build, I've changed the output to "Hello, Day 7!". To debug the program, set a breakpoint by click on the line of source code that writes the message. The breakpoint is indicated by the blue arrow. Then click the rightward arrow icon (looks like a "play" button) to start the debug session on the iPad. It might take a few seconds to build, write the app to the iPad and start the debug session.
Use the Debug|Continue menu option to let the program run. The output is displayed on the iPad. Now, with Xcode you can use the Debug|View Debugging|Take Screenshot of ... menu option to capture a screenshot of the iPad itself. The screenshot is saved on the Desktop as a .png file. Open the file and rotate to landscape view.
Now when we ran the program, an error was generated and sent to the output view. This is caused by Metal Validation being set ON by default. We'll clear this error when we update the project configuration settings.
To summarize for today, we've created an Xcode workspace and project, generated a sample SwiftUI program, editing the source code, compiled and debugged the program on an attached
iPad.
Next time we'll make some edits to the configuration to clear any build warnings, add an Objective-C wrapper and add our library (libava) to the project.












Comments
Post a Comment