Imported and Exported UTIs

October 24th, 2018

Filed under: iOS Development, Mac Development, Xcode | Be the first to comment!

If you create a document-based app project in Xcode, select the app target in the project editor, and click the Info button, you will see sections for imported and exported UTIs. If you have any of the following questions:

  • What is a UTI?
  • When would I use an imported UTI?
  • When would I use an exported UTI?

Keep reading because this articles answers those questions.

What is a UTI?

A UTI is a Uniform Type Identifier that uniquely identifies a file type. Apple has a list of system-declared UTIs, but it’s not being actively maintained. For example a plain text file has the UTI public.plain-text. Most common file types have public at the start of their UTIs.

If you create a new file type, you must create a UTI for it. The UTI should take the form com.CompanyName.FileType.

When to Use an Imported UTI

Use imported UTIs when your app edits file types that it doesn’t own. Suppose you’re developing an image editor. Your image editor edits image files in multiple file formats, such as PNG, JPEG, and TIFF. You would add an imported UTI for each file type the image editor can edit.

When to Use an Exported UTI

Use an exported UTI for any file types your app owns. When you create a new file type for your app’s documents, your app owns that file type, and you should create an exported UTI for the file type. The exported UTI lets the operating system and other apps know about the new file type.

Swift Dev Journal

October 19th, 2018

Filed under: Blog | Be the first to comment!

I want to let you know about a new site I launched, Swift Dev Journal. Swift Dev Journal has articles to help iOS and Mac developers create apps in Swift.

None of the blog posts here are moving. Regarding future writing, longer articles and tutorials about iOS and Mac development will be on Swift Dev Journal. This blog will contain tips and shorter articles, such as the changes in new versions of Xcode, as well as articles that wouldn’t fit at Swift Dev Journal.

Xcode 10: Projects Use New Build System

October 1st, 2018

Filed under: Xcode | Be the first to comment!

In Xcode 10 projects use the new build system by default. If you want to use the legacy build system in a project, choose File > Project Settings. Choose Legacy Build System from the Build System menu.

Xcode 10: See Changed Code in Editor

September 27th, 2018

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

If your Xcode project is under version control, Xcode’s editor highlights the changes you make to the code. When you add or change code, Xcode places a blue bar on the left edge of the editor.


Clicking the blue bar opens a popover to discard the change. For some reason you can’t commit changes from the editor. You can only discard changes.

If you remove code, there may be a blue dot instead of a blue bar in the editor. Click the dot to discard the change and restore the code you removed.

Other Bar Colors

The blue bar on the left side of the editor window is the most common color you’ll see. But Xcode also has the following color bars for source control changes:

  • A gray bar indicates changes you committed locally but did not push to a remote repository.
  • A blue outline indicates upstream changes, changes someone else working on the project made.
  • A red bar indicates the changes you made conflict with upsream changes.


If you do not see colored bars on the left side of the editor, you may need to turn on showing source control changes from Xcode’s Source Control preferences.


Make sure the Show Source Control changes checkbox is selected. Select the Include upstream changes checkbox to see upstream changes in the editor.

Xcode 10: Improved Bitbucket and GitLab support

September 20th, 2018

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

Xcode 10 improves version control support for Bitbucket and GitLab. You can add your Bitbucket and GitLab accounts to Xcode from Xcode’s Accounts preferences.


Click the Add button to add an account. A sheet opens.


Choose Bitbucket Cloud to add your Bitbucket account. Choose to add your GitLab account.

Starting in Xcode 10 you can add your Xcode project to Bitbucket or GitLab from Xcode. Open the Source Control navigator by choosing View > Navigators > Show Source Control Navigator. Select the Remotes folder, control-click, and choose Create Remote. A sheet opens.


Choose your account from the Account menu. Click the Create button to add your project to Bitbucket or GitLab.

Xcode 10: Library Moved to Toolbar

September 17th, 2018

Filed under: Xcode | Be the first to comment!

In Xcode 10 the Library, where you access things like code snippets and user interface elements, is no longer in the lower right portion of the project window. The button to access the Library has been moved to the right side of the toolbar, next to the buttons to show the various editors.


Click the Library button to open the Library in a separate window. Option-clicking the Library button keeps the window open, which helps a lot when you’re building your app’s user interface.

The specific library that opens depends on the file you’re currently viewing/editing. If you’re in a source code file, clicking the Library button will open the code snippets library. If you’re in a xib file or storyboard, clicking the Library button will open the object library that contains the UI elements.

Supporting Dynamic Type in iOS Text Views

September 10th, 2018

Filed under: iOS Development | 1 comment

Dynamic Type on iOS lets people adjust the size of text to make text easier to read. Someone with poor eyesight can use larger text if the app supports Dynamic Type.

You can support Dynamic Type in your iOS app without writing any code. You have to do the following things:

  • Use plain text in the text view.
  • Tell the text view to support Dynamic Type in Interface Builder.
  • Choose a Dynamic Type text style as the text view’s font.

You can perform all these tasks from the attributes inspector in Interface Builder. Select your text view from the storyboard or xib file.


To use plain text in the text view, choose Plain from the Text menu.

Select the Dynamic Type checkbox to support Dynamic Type. If you build your project at this point, you will most likely get the following warning in Xcode:

Automatically Adjusts Font requires using a Dynamic Type text style

Text views in iOS Xcode projects initially use the system font, which does not support Dynamic Type. You must change the font to use a Dynamic Type text style. Click the button on the right side in the Font text field to open a popover to change the font.


Use the Font menu to select a text style. There’s a Text Styles group of menu items. Choose one of them as the font for the text view to support Dynamic Type.

Linker command failed with exit code 1

September 6th, 2018

Filed under: Xcode | 1 comment

If you have done any programming in Xcode, you have come across the following error message when building your project:

Linker command failed with exit code 1.

This error message is frustrating because it tells you nothing besides the fact the linker command failed. You want to know what the real error is so you can fix it.

Find the Real Error

The first step to fixing a link error is to find out what the real error is. To find the real error, open Xcode’s report navigator by choosing View > Navigator > Show Report Navigator.


The report navigator shows recent builds. If you have a linker error, there will be a red icon next to the build, which you can see in the screenshot. Select the build to see the build transcript, the list of steps Xcode took to build the project.


If you have a link error, the build transcript will provide the real error message. Selecting a step from the build transcript makes a little button appear next to the step (The screenshot arrow is pointing to the button). Click that button to see a more detailed build log for that step.

The two most common link errors are undefined symbol and duplicate symbol.

Undefined Symbol Error

An undefined symbol link error occurs when the linker cannot find a data structure name or a function name. The most common cause of an undefined symbol error is a missing framework or library that contains the symbol. Some things to check to fix an undefined symbol error include the following:

  • Make sure you added the library or framework to your project.
  • Make sure the library or framework you added is in the Link Binary with Libraries build phase.
  • If you’re coding in Swift, make sure you imported the library or framework in your code with the import statement.


Header Files

If you’re coding in a language that uses header files, working with header files is another big cause of undefined symbol link errors. Make sure you include the header properly. A common error in C or C++ code is to include a header file that’s not a system header with angle brackets.

#include <MyHeader.h>

Xcode won’t be able to find MyHeader.h in this case because the header is not a system header. Use quotes to include the header file.

#include "MyHeader.h"

Search Paths

If none of the fixes I mentioned earlier work, you may need to add search paths for the library, framework, or header file so Xcode can find them. Xcode has a Search Paths collection of build settings, which you can access from the project editor.


Duplicate Symbol Error

A duplicate symbol error occurs when the linker finds two or more data structures or functions with the same name. People using Xcode to learn C++ can run into this error if they create a command-line tool project. The command-line tool project includes a main.cpp file that has a main function in it. If you add a new file with its own main function and forget to remove the one Xcode created for you, you get a duplicate symbol error.

When trying to fix a duplicate symbol error, the first thing to check is that you haven’t defined a symbol twice in your project. Xcode’s find navigator helps you find all occurrences of a given symbol in your project.


If you’re using external frameworks or libraries, make sure your symbol names aren’t duplicates of symbols in the framework or library. If you are using custom namespaces in your code, make sure you set up the namespaces properly.

Creating a Keyboard Input Accessory View

August 10th, 2018

Filed under: iOS Development | Be the first to comment!

In this article you’ll learn about keyboard input accessory views and how to add them to your iOS app to make text editing smoother.

Adding a keyboard input accessory view isn’t too difficult. Add a new xib file to your project for the view. Load the view from the xib file. Set the input accessory view to the view you loaded. There’s less than 10 lines of code involved.

What Is a Keyboard Input Accessory View?

A keyboard input accessory view is a view that appears above the iOS onscreen keyboard. The default iOS behavior is to have no input accessory view, but nothing is stopping you from adding one. A common use of an input accessory view is to show a toolbar with frequently used commands when typing text. The writing app Ulysses uses an input accessory view to insert Markdown characters into the text. If you were writing an iOS HTML editor, you could show a toolbar with buttons to insert the most common HTML tags.

Keep in mind that a keyboard input accessory view has type UIView?, which means the accessory view can be any kind of view. The accessory view does not have to be a toolbar. I’m using a toolbar as an example in this article because many apps have a toolbar as the accessory view.

Step 1: Create a Xib File for the Accessory View

The first step in creating a keyboard input accessory view is to create a new xib file and add it to your project. In Xcode choose File > New > File to add a new file to your project. The xib file templates are in the User Interface section under iOS.


The empty xib file is the best option for toolbars. If you want a custom view for the accessory view, you can choose View instead of Empty.

Step 2: Add the Accessory View to the Xib File

Take a toolbar (or whatever kind of view you want to use) from the object library and drag it to the canvas. The toolbar has one item in it. Add bar button items to the toolbar to fill the toolbar.

While you’re in Interface Builder go to the identity inspector and set the class for the File’s Owner object in the xib file.


Set the class to the view controller where you’re going to use the input accessory view. By setting the File’s Owner class to the view controller, you will be able to connect the controls in the input accessory view to IBActions in the view controller to respond to tapping the controls. In the xib file make a connection from the controls to File’s Owner to connect to IBActions.

Step 3: Load the Accessory View from the Xib File

Now it’s time to write some code to load the input accessory view. Call the Bundle class’s loadNibNamed function to load a xib file from the app bundle. Supply the name of the xib file as the first argument. Pass self as the owner argument, and pass nil as the options argument.

Calling loadNibNamed returns an array of the top level objects in the xib file. The input accessory view is the only top level object in the xib file you created so accessing the view is easy. Use the first property to access the first item in the array and grab the accessory view. The last code to write is to set the text view’s input accessory view to the view you loaded from the xib file. The following function sets up an input accessory view for a toolbar:

func setupInputAccessoryView() {
    let nibContents = Bundle.main.loadNibNamed("KeyboardInputAccessoryView", 
        owner: self, options: nil)
    if let toolbar = nibContents?.first as? UIToolbar {
        textView.inputAccessoryView = toolbar


There’s no more code to write. If you build your project and show the keyboard, the toolbar will appear at the top of the keyboard.

I noticed a bug in the iOS 11 Simulator where the toolbar would stay at the bottom of the screen after dismissing the keyboard. I did not run into this issue on iOS devices. If the toolbar is not going away, set the isHidden property of the input accessory view to true when dismissing the keyboard. Set isHidden to false when showing the keyboard.

Make UIDocument File Wrapper Appear as Single File

August 3rd, 2018

Filed under: iOS Development | 1 comment

I was recently working on an iOS document-based app that saves the document in a file wrapper. When I looked in the document browser, the document appeared as a folder instead of a single file. For Mac document types Xcode has a checkbox to select to make the document appear as a single file, but iOS document types do not have this checkbox. How do you make the document appear as a single file?

To make the document appear as a single file in the document browser, the document’s exported UTI must conform to the UTI In Xcode’s project editor, add to the Conforms To text field for the exported UTI.


Rebuild your project. Any documents you save should appear as single files instead of folders.