November 15th, 2020
Filed under: Xcode | Be the first to comment!
In Xcode 12 Apple consolidated many of their iOS app project templates into one template: App. If you are following a tutorial written for an older Xcode version that has templates like single view app and master-detail app, choose the App template.
October 3rd, 2020
Filed under: None | Be the first to comment!
I see many people who ask a programming question on Reddit and do one of two things to show their code:
By doing these things, the people asking the question make their code extremely difficult to read, making it less likely they will get an answer.
Notice how the code isn’t indented properly in the inline code block above. This sample isn’t too bad, but I have seen long inline code blocks that are almost unreadable.
The way to make a code listing readable on Reddit is to create a Markdown code block. Start by clicking the Markdown mode button on the right side of the toolbar above the text view for writing the post.
Write your post in Markdown. Any paragraphs you write will appear as normal body text in the final post. To create a code block, put three backticks on the line above the code listing and three more on the line below the listing.
```
// Put your code listing here
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
}
```
Then we you click the Post button, your code listing will appear in a block similar to the listing above, minus the backticks above and below the code.
By using Markdown code blocks for code listings in Reddit, your code will be much easier to read. People will be more likely to answer your question because you took the time to make an easy to read listing.
October 1st, 2020
Filed under: Xcode | Be the first to comment!
As part of Xcode 12, Apple added project templates for creating SwiftUI apps that run on both iOS devices and Macs. In the Xcode 12 betas, these project templates appeared in the Multiplatform section.
When Apple released iOS 14 in September, they also released Xcode 12.0. If you install Xcode 12.0 and create a project, you will see that the App and Document App projects are missing from the Multiplatform section. What happened?
The App and Document App templates require the macOS 11 SDK. Because macOS 11 was still in beta when Xcode 12.0 shipped, Apple did not include the macOS 11 SDK in Xcode 12.0. That’s why the App and Document App templates are missing in Xcode 12.0. No macOS 11 SDK, no App and Document App templates.
If you want to use the App and Document App templates, you must install Xcode 12.2, which includes the macOS 11 SDK. Apple will release Xcode 12.2 when macOS 11 ships. If you can’t wait for macOS 11 to ship, download the Xcode 12.2 beta.
UPDATE: November 2020
Xcode 12.2 is now available at the Mac App Store, and it includes the multiplatform SwiftUI project templates.
August 11th, 2020
Filed under: Xcode | Be the first to comment!
If your Xcode project has multiple targets and you add a Swift package, Xcode will let you add the package to only one of the targets. How do you add the package to the other targets?
Select a target from the project editor. Click the Add button in the Frameworks, Libraries, and Embedded Content section.
A sheet will open with a list of frameworks and libraries that you can add. The Swift package will appear in the list.
April 29th, 2020
Filed under: Xcode | Be the first to comment!
People constantly post on Apple’s developer forums complaining that when they try to install Xcode, an alert opens saying they don’t have enough disk space to install it. These people always say they have enough space because they have more free space on their disk than the Xcode download. Usually the person asking the question has 15–20 GB of free space on their startup disk.
The Xcode file that you download is a compressed file. You need enough disk space to store both the compressed file you downloaded and the expanded file. Suppose your Xcode download is 8 GB. The expanded file is going to be bigger than that. Xcode 11.4.1 takes up 17.39 GB on my Mac. At this point you need 25.39 GB of free space. Add in some temporary storage space for swapping files, and you need a minimum of 30 GB of disk space to install Xcode.
30 GB of disk space is just an example. That may not be enough free space, especially for newer Xcode versions. Xcode releases keep getting larger over time so the amount of free disk space you need will increase as well.
If an alert opens saying you don’t have enough space to install Xcode, you don’t. Have enough free disk space that is at least 5 times the size of the compressed Xcode file you are going to download from Apple. I know that can be hard to do, especially if you are using a laptop with a 128 GB SSD, but you have to free up the space.
The app DevCleaner for Xcode can free up gigabytes of disk space by removing caches and other old files that accumulate over time.
January 23rd, 2020
Filed under: Xcode | Be the first to comment!
Xcode 11 provides a subtle button to export a Mac app archive. In the Organizer, select an archive and scroll so you can see the Status column for the archive. Move the cursor over the Status column to make the Export App button appear.
October 19th, 2019
Filed under: Version Control, Xcode | Be the first to comment!
This post lists all the changes I found in Xcode 11 on version control.
Xcode 11 adds a code review button to the toolbar that lets you view the changes you made to the currently selected file.
The code review button is the button with the two arrows facing right and left.
When you make changes to your source code, a blue bar appears on the left side of the editor next to the changed code.
If you click the blue bar, a popover opens that lets you discard the change you made to that block of code.
In Xcode 11 you can stash uncommitted changes in Xcode. Stashing changes lets you temporarily store changes you make to your code so you can switch branches. Stashing is potentially dangerous. If you mistakenly remove a stash, you can’t get it back. It’s safer to create a temporary branch and commit your changes to the temporary branch.
Choose Source Control > Stash Changes to stash your changes. A sheet opens for you to enter an optional message. Click the Stash button to complete the stash.
You can view your stashes from the source control navigator. The stashes are in the Stashed Changes folder. Select a stash to view the changes you made.
Right-clicking on a stash opens a contextual menu that lets you apply and delete your stashes.
Xcode 11 adds support for cherry picking commits. Cherry picking involves taking a commit from one git branch and applying it to another.
To cherry pick a commit, switch to the branch where you want to apply the cherry pick. Choose Source Control > Cherry Pick.
A sheet opens for you to enter a revision identifier, which is the identifier git supplies for a commit. Finding the revision identifier for the commit you want to cherry pick is the hardest part. When you enter a valid identifier, the commit will appear in the list of commits. Select the commit and click the Cherry-Pick button to cherry pick the commit.
September 25th, 2019
Filed under: Xcode | Be the first to comment!
When you create an iOS or Cocoa app project in Xcode 11, there is a User Interface menu in Step 2 of the New Project Assistant.
For iOS projects the user interface choices are SwiftUI and storyboard. For Mac projects the user interface choices are SwiftUI, storyboard and xib file.
Xcode defaults to using SwiftUI as the user interface for new Xcode 11 projects. If you want to use storyboards and view controllers for your app’s user interface, make sure you choose Storyboard from the User Interface menu.
September 17th, 2019
Filed under: Xcode | Be the first to comment!
Xcode 11 makes it easier to open new editors. You can open a new editor without switching to the Assistant Editor. Either choose File > New > Editor or click the Add Editor button in the jump bar.
Xcode defaults to adding editors to the right, stacking the editors horizontally. If you want new editors to appear below the current editor, choose File > New > Editor Below. When you do this, the menu item will change from Editor Below to Editor on Right.
Choosing View > Change Editor Orientation will toggle stacking editors vertically and horizontally.
June 17th, 2019
Filed under: Xcode | Be the first to comment!
Suppose you have an Xcode project with spaces in the name.
My App
In your unit tests you want to import the module so you can access your app’s classes in your unit tests. If you import the app project with the spaces,
@testable import My App
You’ll get errors from the compiler.
How do you import the project name? Replace the spaces with underscores.
@testable import My_App
Now you can access your app’s classes in your tests.