banner



How To Set Up Xcode

Xcode tutorial banner

Xcode Tutorial For Beginners(Updated for Xcode 11)

by Chris Ching


This guide will demystify Xcode for you and teach you what you need to know in order to start building apps!

Xcode icon

You'll acquire:

  • Where to download Xcode and how to fix it up
  • The 5 main parts of the Xcode development surroundings and how to navigate effectually
  • How to code and build your user interface with Xcode
  • How to use the iOS simulator to exam your app

The Complete Xcode 11 Tutorial:

  1. What is Xcode? (and what's new in Xcode 11)
  2. Download Xcode and install information technology
  3. How to utilise Xcode
  4. Find your files in the Navigator Expanse
  5. Write code in the Editor Area
  6. Build your user interface (Storyboards or SwiftUI)
  7. Configure elements with the Utility Area
  8. Run and build your project using the Toolbar
  9. Test and fix bugs with the Debug Console
  10. Run your app using iOS Simulator (or your device)
  11. Learn to code with Xcode Playgrounds
  12. Submit your app with the Xcode Organizer
  13. Conclusion

What is Xcode?

Xcode is an awarding that developers use to build apps for Apple's various platforms such equally iPhone, iPad, Macs, AppleTV and Apple tree Scout.

Xcode Requirements

Xcode is available for Macs only merely there are culling options for PC users. I also often go asked if yous can run Xcode on iPad and unfortunately the respond is no.

It requires macOS ten.14.4 or later and 7.6 GB of difficult drive infinite. If you don't meet the minimum requirements, you can endeavor to update Xcode using this method (at your ain risk).

The latest version of Xcode is xi. If you want to check what version of Xcode you currently have, merely launch it and in the welcome screen, you'll see it conspicuously stated.

Xcode requirements
Xcode requirements

What's new in Xcode 11?

Xcode 11 brings lots of new features such as support for Swift 5.1, Apple's latest iteration of the Swift programming language, SDKs for iOS 13, tvOS 13, watchOS half dozen and macOS Catalina ten.xv.

Xcode 11 welcome screen
Xcode 11 welcome screen

Each of those platforms has changed since their previous iteration and Xcode 11 allows you to build apps to utilize these new features.

In terms of how Xcode itself has changed as an IDE (integrated development environment), there are many new features to make information technology easier for you to build software.

I've made a video going through all the changes below:

(Note: this is going to be nearly relevant for people who take used previous versions of Xcode before. If you're a beginner, I recommend that yous skip this section for now)

Should you update to Xcode 11?

The biggest incentive to update is the ability to piece of work with the latest version of the Swift programming language also as Apple'south new declarative UI framework, SwiftUI.

Apple keeps a pretty tight leash on the App Shop and over fourth dimension, they enhance the requirements on apps that are published. Eventually, yous will have to update to Xcode eleven in order to build apps that use the latest versions of iOS.

If your Mac is pretty new (2015+), there's no disadvantage to updating and working with the latest technology.

However, if your Mac is too old to handle the systems requirements of Xcode xi and you're just starting to learn iOS development, there's no trouble with using an older version of Xcode just to learn.

The easiest way to download Xcode for free is through the Mac App Shop. Click the link to go to the listing.

Yous can also download information technology manually if you don't have the Mac App Store. Just visit the Apple Developer page for Xcode.

If you download it from the Mac App Store, then updating Xcode becomes really easy since yous can simply download and install the update through the store.

Download the latest version of Xcode from the Mac App Store
Download the latest version of Xcode from the Mac App Store

Xcode Older Versions

If you're looking for older versions of Xcode, cheque out this folio. Y'all tin can download previous versions of Xcode too as betas versions. You're going to have to sign up for a costless Apple ID if yous don't have 1 because the betas are only available for members of the Apple tree Developer Plan.

Download older versions of Xcode
Download older versions of Xcode

Xcode on Windows

Unfortunately Xcode is just for Macs but if y'all're using a PC, there are alternative means to run Xcode on Windows. Check out my guide for options!

Xcode Alternatives

I highly recommend you use Xcode if at all possible. The reason is that when Apple announces new changes (similar they did this year with SwiftUI), they build support for those new technologies straight into Xcode.

AppCode IDE
AppCode IDE

Other third party IDEs take to play catch-up and it might non even exist guaranteed that they'll roll out support for the new changes from Apple at all!

Having said that, if you still desire to check out some alternatives to building iOS apps with Xcode, cheque out the post-obit:

  • AppCode
  • Visual Studio Lawmaking
  • React Native
  • Palpitate
  • Xamarin
  • PhoneGap
  • Appcelerator

Video walkthrough of the Xcode interface
Xcode cheatsheet

I have an awesome cheatsheet that I created for referencing all the keyboard shortcuts I use! It'll come up in handy every bit you learn to utilize Xcode for yourself. You can download the cheatsheet here.

By the end of this chapter, you'll take a great understanding of how to navigate the development surround and how to create your kickoff Xcode project.

Before we dive in, continue this Apple Documentation for Xcode handy.

Let's now await at the diagram below. If your interface looks different, make sure you have Xcode 11 and non an earlier version.

Xcode 11 User Interface

The reason this is a dandy diagram is because it lets me refer to these different sections of the interface and you can refer back to this diagram to see what I'm talking well-nigh!

As yous can see from the diagram, there are 5 major areas: the Navigator, Editor, Utility Area, Toolbar and Debug Surface area. We'll cover each area in detail afterwards but for now, let'southward talk well-nigh general navigation of Xcode.

Keep in mind that yous tin adjust the size of each of those panes past hovering your cursor over the boundaries of each surface area and dragging.

You can also show and hibernate the various areas as needed via the "View" buttons in the upper right hand corner:

Xcode toggle view buttons

This can be helpful, for instance, when you're writing code and you don't need the debugger area or the utility area. Then you tin use the View buttons to hibernate those two panes to give your editor more than visible space.

Xcode editor area
Xcode editor expanse

Alright, allow's go through the Navigator surface area at present!

In this pane, there are a bunch of different navigators that you tin switch between using the Navigator Selector Tab Bar (come across screenshot below).

Since there are so many (eight!), I'thou just going to talk virtually the 3 most common ones you'll use as a beginner: the Project, Search and Issue navigators.

The Xcode Project Navigator

The Project Navigator is where y'all'll see all the files associated with your project. This is the default tab you'll run across when yous create a brand new Xcode project.

Xcode file navigator
Xcode Project Navigator

Organizing your files

Inside the Project Navigator, you can too create Groups to organize your files in. Think of them similar folders. You lot tin create a new Group and then drag your files into them to organize your projection a little fleck.

Adding groups to Xcode
Creating new groups to organize your Xcode project

Creating and adding new files

You tin can also right click on the Projection Navigator and create new files or add existing files to your projection. Or you lot can elevate folders or files from your computer directly onto the Project Navigator and will popup a dialog asking how you want to add the files.

Xcode new file dialog
Xcode new file dialog

Editing files

If you click on a file in the Project Navigator, information technology will brandish the contents of that file in the Editor Surface area so that you can edit that file.

The Xcode Search Navigator

With the search navigator tab, you can easily await for pieces of text in your project.

Xcode search navigator
Xcode Search Navigator

You'll find yourself using this a lot when you're looking for a specific property, method or variable and you lot tin't remember exactly where it is.

One of my favorite Xcode shortcuts is cmd+shift+F. Hitting these keys is going to switch to the Search Navigator to perform a project-wide search. This actually helps when yous demand to make a change in multiple places in a projection.

The Xcode Issue Navigator

The consequence navigator shows you all the bug with your app.

Xcode issues navigator
Xcode Problems Navigator

When you build and compile your awarding to test, if there are some problems where Xcode can't build your app, it will halt and show you the red colored errors in the issue navigator. You can click on an fault and it will show y'all in the editor area which file and line it'southward failing at.

It will also testify yellow Warnings in the result navigator. Although resolving warnings is not necessary for building your app, they're warnings that there may be potential bug.

Similarly, when you're building your user interface in Xcode, whatever errors will as well show itself in the Issue Navigator.

The editor area is where we'll probably be spending about of our fourth dimension! This is where all the coding, configuration and user interface building happens.

The Editor Area changes depending on what file you lot take selected.

If you lot accept a Swift file selected, it'll prove you lot the code editor similar beneath. However, if y'all accept a user interface file (like a Storyboard) selected, then it'll show yous Interface Builder which is a visual editor for your user interface. Subsequently in this commodity, I'll talk more about Interface Builder.

Let'south become through the Editor Area in the context of editing code files first.

Writing Code

Click on a Swift file from the Project Navigator and you'll see something like this:

Xcode editor area
Xcode lawmaking editor expanse

If you want to prove line numbers in the gutter to the left of the editor, you can enable line numbers in the Xcode preferences. The Dark theme can also exist enabled in the preferences.

Bated from that, you lot write code in the big text editing area!

Let's go through some handy tips to make your code writing experience more enjoyable:

Navigation and Breadcrumb

There are these little dorsum and frontwards arrows in the upper left corner of the editor expanse. Unfortunately these arrows aren't labeled in the trusty Xcode interface diagram at the offset of this commodity so I'll call them "Xcode back and forward arrows" and evidence you an epitome of them here:

Xcode breadcrumb and navigation bar
Xcode breadcrumb and navigation bar

These guys are actually pretty useful. They human activity like the back and frontwards buttons on your browser and they let you navigate to previously viewed files.

Another style to apace get to the file you need is to use the Jump Bar. Click any segment of the Breadcrumb and it'll show you lot a bill of fare of files or groups that you can select at that hierarchy level.

The jump bar allows you to quickly drill downwardly through your groups and find the file you need.

Click a segment of the breadcrumb to access other files and folders
Click a segment of the breadcrumb to admission other files and folders

If you click the tail segment of the jump bar (which is the current file you lot're looking at), it will open upwards a menu showing you lot all the methods in the file to bear witness give you an overview of what methods are in that file and to allow you to jump to a specific method.

See an outline of the file and quickly jump to specific methods or sections
Run into an outline of the file and quickly leap to specific methods or sections

Finding and replacing inside the file

Just hitting Command-F to bring up a search popup in the upper right corner that volition expect for whatever you type in within the current file. This is as well a cracking way to spring to various areas of your file. You can also use this popup to do replacements within your file.

Jumping to definitions

If y'all're looking at some code and you encounter a classname that y'all want to leap to the definition of, you lot can concord downwardly Control and click the classname to chop-chop spring to that file.

Right click a method or class to jump to its definition
Right click a method or class to jump to its definition

The breakpoint gutter

A breakpoint is an Xcode debugging characteristic that lets you intermission the execution of code at a specific line of code.

The breakpoint gutter (where the line numbers are) is where you lot tin click to prepare breakpoints at certain lines of code.

When you ready a breakpoint, yous'll see a bluish indicator appear. To turn off a breakpoint, just click the bluish indicator again and it volition dim out.

Xcode breakpoints
Xcode breakpoints

If you want to completely remove the breakpoint, yous can click and elevate the blue indicator off of the breakpoint gutter.

To view a list of all the breakpoints that are set up in your project, there's a "breakpoint navigator" tab in the Navigator expanse.

There'southward also a global toggle to turn breakpoints on or off at the top of the editor area which we'll see when we review the toolbar.

Don't worry if you can't remember everything correct at present. We'll exist working with all of these areas and when y'all offset coding, this volition all become 2nd nature to y'all after a calendar week.

Configuring Xcode project properties

The root node of the projection navigator is your Xcode project file (indicated past the bluish icon). If you click that, the projection backdrop will open in the editor area.

Xcode project configuration and properties
Xcode project configuration and properties

You'll visit the project properties screen quite a bit during the process of building your app. In this screen, you can configure things like:

  • Set the name of your app
  • The bundle identifier (your unique ID for the app)
  • Allow your app to work on multiple device orientations
  • Prepare the version of your app
  • Prepare the minimum required iOS version that your app can exist install on
  • Add additional Apple frameworks and libraries
  • Betoken your code signing options which are mandatory for submitting your app to the App Store (if you accept lawmaking signing errors, this is where y'all'd fix it!)
  • In that location'due south a lot more!

Xcode 11 brings ii different ways of building the user interface (UI) for your app: Storyboards or SwiftUI.

When you create a new Xcode projection, you'll see a dropdown to cull one of these two options:

Xcode new project select a user interface option
Xcode new project select a user interface pick

Storyboards are interfaces built with visual drag and drib in the Editor Area using Interface Builder.

Xcode project using storyboards
Xcode projection using storyboards

SwiftUI was released in late September 2022 as a new way to build user interfaces past writing code. Xcode eleven has a special Preview Sail pane that shows your user interface change in real time as you write the code to modify your user interface.

Should you utilise Storyboards or SwiftUI?

As a beginner, most of the tutorials you lot'll discover on the cyberspace right now will based around Storyboards and UIKit since SwiftUI was just released. Most of my tutorials are based on Storyboards because it was the easiest way for beginners to grasp.

However, since Apple is moving forrard with SwiftUI, it'due south a improve investment for the hereafter merely at the present moment, you'll exist express with the corporeality of assistance and educational content you can find on it. I've written a SwiftUI tutorial so check that out if yous want to move forrard with that!

In this Xcode tutorial nonetheless, I'll evidence you how to work with both options within the Xcode Editor Expanse.

How to use Storyboards and Interface Builder

If you lot chose Storyboards as your UI edifice selection when you lot created the Xcode project, then your project will have a file called Chief.Storyboard.

Click this file and the Editor Area volition change to the visual UI designer known as Interface Architect.

Xcode interface builder
Interface Builder

The Object Library

The Object Library is a pane where you can search for user interface elements from UIKit. These elements are things like buttons, sliders, labels and textfields.

You can drag and drop them onto the view but in order to size and position them, yous need to utilize the Car Layout arrangement.

Adding Auto Layout constraints

Auto Layout is a system to arrange and size the elements on the view based on what rules (known as "Constraints") you lot add together to the elements.

For instance, you might add a constraint saying that an element should be 20pt below the element higher up information technology. I have an introduction video to the Xcode Machine Layout system here:

With enough constraints in place, the Auto Layout organisation has plenty information to lay out the user interface. However, having too many constraints may result in conflicts where two or more than constraints have opposing demands. In this example, Xcode volition notify you of the error and you'll accept to fix it.

To add together constraints, use these buttons in the lower right corner of Interface Builder:

Adding Auto Layout constraints in Xcode
Adding Auto Layout constraints in Xcode

The Certificate Outline

The Document Outline is the skinny panel in betwixt the Navigator Area and Editor Surface area. It only shows up when you're looking at an Interface Architect file like the Storyboard.

It'south a very of import pane because it shows y'all the visual hierarchy of all the elements that you've added to the view. It likewise lists all of the Auto Layout constraints you've added.

Document outline shows the elements in your view
Document outline shows the elements in your view

The visibility of the Certificate Outline can also exist to toggled with this small button in the lower left corner of Interface Builder:

This tiny button toggles the visibility of the document outline
This tiny button toggles the visibility of the document outline

Assistant Editor

The Banana Editor view which will prove y'all the accompanying file to the file you're currently looking at. It looks like a two pane view.

If you're working with Storyboards, the Assistant Editor will be helpful for connecting user interface elements from the Storyboard view to the code file and then that you tin manipulate those elements via code.

For example, if you're looking at a view in the Storyboard, the right pane will show y'all the linked class file for that view. Each pane also has independent jump bars, so y'all tin can as well utilise that to change what file each pane is displaying.

The Assistant Editor is useful for connecting elements in your storyboard to your code
The Assistant Editor is useful for connecting elements in your storyboard to your lawmaking

To open up the Assistant Editor, you can become into the Editor carte du jour and cull Banana.

Open the Assistant Editor
Open the Assistant Editor

For more practice using Storyboards, cheque out my beginner series on YouTube.

How to use SwiftUI and the Preview Canvas

If you lot created your Xcode projection choosing SwiftUI for your user interface selection and then yous won't get a Master.Storyboard file but you'll see a ContentView.swift file instead. This file is where y'all'll build your first SwiftUI user interface.

The ContentView.swift is where your UI code is
The ContentView.swift is where your UI lawmaking is

The Preview Canvas

The canvas is a pane abreast your lawmaking editor where yous'll encounter a live preview of your user interface.

Xcode Preview Canvas
The Xcode SwiftUI Preview Canvas

If you don't see it, go to the Editor menu and select Canvas. Note that it needs at least macOS 10.15 to run. If yous don't have that, then you can still launch your app in the iOS Simulator to see the UI of your app.

Show the canvas pane in the Editor Area if it's hidden
Show the sheet pane in the Editor Area if it's hidden

Using the Object Library for SwiftUI

The Object Library shows you a list of SwiftUI elements you can add to your UI. You lot can search for what you need so drag and drop it into the code editor and it'll generate the code for you.

SwiftUI Object Library
The SwiftUI Object Library

We're not going to dive deeper into how to build UIs with SwiftUI since information technology's a lot of lawmaking writing and this is a tutorial for how to use Xcode. If you're interested in learning how to utilise SwiftUI, bank check out my SwiftUI tutorials on YouTube.

The Xcode utility area as a variety of Inspectors to view details virtually the file, chemical element or piece of code that you lot're looking at.

In this chapter, nosotros'll go through a few scenarios of how you'll use the diverse inspectors.

Xcode utility area
Xcode Utility Surface area

The File Inspector

The File Inspector is the offset tab in the Utility Area and information technology shows details about the current highlighted file in the File Navigator.

Information such as the physical location of where the file is on your hard drive and other file properties:

The Xcode file inspector
The file inspector

The Quick Help Inspector

The Quick Help Inspector shows you documentation about the method, course or keyword that your typing cursor is currently on.

This is very useful because yous don't have to launch the developer documentation if you're looking for some quick information about how to utilize that slice of lawmaking.

The quick help inspector
The quick help inspector

Suffice to say, this inspector will draw a blank unless your typing cursor is in the code editor over a valid method, course or keyword.

The Attributes Inspector and Size Inspector

These inspectors will only prove up equally tabs in the Utility Area when you've selected a user interface element in the Storyboard.

These two inspectors allow yous to customize the chemical element.

Xcode attributes inspector
The Attributes Inspector
The size inspector
The Size Inspector

We've talked about some of the buttons on this tool bar already. Permit's start from the left.

Xcode toolbar
The Xcode Toolbar

Building and running your Xcode project

The left-most button is the run button. This will build and run your application and launch your app in the iOS Simulator. The button beside it will cease the execution of your application and return you lot to Xcode.

If you click and concord down the Run button, yous'll get more options to run your app:

Build and run your project
Build and run your project

Test to run your unit tests if yous have them in your project.

Profile to measure various aspects of your application such as performance, memory usage and more.

Clarify to let Xcode analyze your code and check for potential leaks or bad practices.

Selecting an iOS Simulator to examination your app on

The dropdown beside the Cease button indicates which build target you want to run (your can run an Apple Watch target too) and y'all tin can besides choose if yous want to run it under the iPhone or iPad simulators (or unlike version if you have them installed). The selection "iOS device" is to run your app on your device if yous accept it plugged in and properly provisioned (which needs a whole tutorial in itself!).

Choose a target simulator to run your app on
Choose a target simulator to run your app on

The Xcode Status Bar

The status bar will show you what Xcode is currently doing. You'll also meet little indicators for errors and warnings if they exist in your project.

Xcode status bar
Xcode condition bar

The Object Library and hiding/showing panes

And finally in the far correct side of the toolbar, we have the Library button (which we've talked about in the user interface section of this guide), Lawmaking Review push (used to review code changes if you're using source control) and buttons to toggle various panels on or off.

Xcode toggle view buttons

The debug area will prove you console output and the state of various variables when you run your application.

Xcode debug area

You'll be using this a lot while debugging your code and trying to figure out why things aren't working out the style yous expect them to!

If you'd like to learn how to debug your lawmaking using Xcode debugger tools, check out my video tutorial here:

Xcode xi comes arranged with a wonderful iOS Simulator for you to test your application on.

In fact, you tin can use the iOS simulator for near of your evolution and then find a device to test on when y'all're nearly done.

You'll notice simulators for all of the latest Apple Devices.

The iOS Simulator that comes with Xcode
The iOS Simulator that comes with Xcode

Yous tin can actually do a lot with the Xcode simulator including:

  • Device rotation
  • Simulating various GPS coordinates
  • Device milk shake
  • Simulating depression retention scenarios

If you want to exam various network or low bandwidth weather, there's a tool called Charles Proxy that works brilliantly. I've written a Charles Proxy Tutorial that you can read.

How exercise yous install an app on an iOS device?

I have a detailed guide on how to deploy your app on an iOS device.

4 steps to install your app on a device:

  1. When you lot're ready to exam on a real device, you can just plug it in via USB.
  2. Y'all'll see a prompt on your phone asking if you lot desire to trust this computer. Tap on "Yes".
  3. Xcode volition ask if yous desire to use this device for evolution. Tap on "Yes".
  4. Then you'll encounter your device in the listing of devices you lot can deploy your app on (it'll sit down to a higher place all the simulators)
Deploying your app on your device
Deploying your app on your device

An Xcode Playground is a light weight editor for you to try out some lawmaking. It's non a full-fledged Xcode projection and it isn't intended to be used for building an app.

An Xcode playground
An Xcode playground

Playgrounds are great equally a instruction tool, learning tool or for experimentation.

Note: There's besides an educational iPad app that Apple released chosen "Swift Playgrounds". Don't misfile that with what we're talking about here.

To create a new Xcode Playground, become up to the menu File, New, and so Playground.

Start a new Xcode playground
Outset a new Xcode playground

For more information on how to utilize Xcode Playgrounds, check out this WWDC video.

If you become up to the Window card, you lot'll observe a carte item called "Organizer".

Opening the Xcode Organizer
Opening the Xcode Organizer

This brings up a separate window where you can exercise various activities related to your app in the App Shop. Nosotros'll become through these various activities in this affiliate.

Xcode Organizer
The Xcode Organizer

Archives

An annal is what Xcode calls a build of your app. When yous're set up to submit your app to the App Shop, y'all create an archive which is all of your code and resource files into ane neat trivial parcel.

All of your archives are listed in the Archives section of the Organizer.

Selecting one of your archives will give y'all an selection to do various things with it, including sending it to the App Shop. Check out my guide on how to submit your app using App Store Connect when y'all're prepare.

Crashes, Energy, Metrics

These three sections in the Organizer volition show you diverse metrics nerveless from your app being used by existent users.

This data is really valuable to utilize for improving your app in regards to making it more robust (less crashing) and more efficient (using less resources)

In this Xcode tutorial, y'all've learned most the various parts of the IDE and how to utilize Xcode for writing code and building user interfaces.

What's Next?

Set to get your hands dirty in Xcode and build something? Desire to larn Swift programming too?

Here are some of my resources:

  • Go my handy Xcode cheatsheet with all the keyboard shortcuts that I use!
  • The ten Step Process To Make An App: Learn the iOS app development process with this step past step guide.
  • The Consummate Swift Tutorial for Beginners: Learn Swift programming with my Swift guide designed with the beginner in mind.
  • vii Day App Activity Plan: Plan out your app and finally get started turning your app thought into reality.
  • Xcode for Windows: On a PC? Don't let that stop y'all. Use one of the options in this guide.
  • iOS Training that Actually Pays Off: My flagship training programme helps non-coders learn how to code and brand apps.

Were you able to learn how to use Xcode with this tutorial?

If this guide helped y'all, please let me know by leaving a quick annotate below. I beloved hearing from my readers and I capeesh that y'all're learning with me. Talk soon!

Source: https://codewithchris.com/xcode-tutorial/

0 Response to "How To Set Up Xcode"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel