How to Show Source Code on Reddit

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:

  • They show a screenshot of their screen.
  • They use the inline code setting instead of creating a code block.

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.

RedditLongInlineListing

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.

RedditPostUI

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.


Where Did the Multiplatform SwiftUI Project Templates Go in Xcode 12.0?

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.

Xcode12MultiplatformProjectTemplates

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.


Adding a Swift Package to Multiple Targets

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.

FrameworksAndLibraries

A sheet will open with a list of frameworks and libraries that you can add. The Swift package will appear in the list.


Disk Space Required to Install Xcode

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.

You Need More Free Space Than the Download Size

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.

Summary

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.


Xcode 11: Export Mac App Archive

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.

Xcode11ExportApp


Xcode 11 Version Control Changes

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.

Code Review Button

Xcode 11 adds a code review button to the toolbar that lets you view the changes you made to the currently selected file.

CodeReviewButton

The code review button is the button with the two arrows facing right and left.

Discarding Changes Using the Editor

When you make changes to your source code, a blue bar appears on the left side of the editor next to the changed code.

SeeVersionControlChangesInEditor

If you click the blue bar, a popover opens that lets you discard the change you made to that block of code.

Stashing Changes

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.

ViewStashes

Right-clicking on a stash opens a contextual menu that lets you apply and delete your stashes.

Cherry Picking

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.

CherryPickSheet

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.


Xcode 11: User Interface Menu for New Projects

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.

Xcode11UserInterfaceMenu

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.


Xcode 11: Opening Editors

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.

Xcode11AddEditorHighlighted

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.


Unit Testing a Project with Spaces in Its Name

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.


Xcode Bug Creating Bitbucket Repositories

March 10th, 2019

Filed under: Version Control, Xcode | Be the first to comment!

Xcode 10 has bug/limitation in creating Bitbucket repositories for your projects. If the name of the repository has uppercase letters, such as MyProject, an alert pops up when you create the repository with the helpful message An unknown error occurred.

The workaround is to use all lowercase letters in the repository name, such as myproject.