Xcode Tutorial - Step by Step for Beginners

CodeWithChris
3 Oct 202256:52

Summary

TLDRThis tutorial offers an in-depth guide for beginners on using Xcode to build iOS apps. It covers installing Xcode, creating a new project, and navigating its interface. The instructor emphasizes using Swift UI for modern app development and demonstrates coding a basic user interface. The video also explores the asset library, debugging tools, and testing apps on simulators and real devices. Finally, it touches on publishing apps to the App Store and using Xcode's features for efficient coding.

Takeaways

  • 📘 Xcode is the official software by Apple for building iOS apps, and even professionals use it daily.
  • 🚫 For beginners, it's recommended to avoid Xcode betas due to potential bugs and ongoing changes that can complicate learning.
  • 🔍 When starting a new project in Xcode, selecting the correct options such as platform (iOS, macOS), user interface technology (Swift UI, Storyboard), and programming language (Swift, Objective-C) is crucial.
  • 💼 The project file with the '.xcodeproj' extension is essential as it links all project files into a single package.
  • 🖼️ Resources like app icons, colors, and images are managed in the asset catalog, which is important for maintaining a consistent UI across different devices.
  • 🔑 The unique bundle identifier, usually in the format of 'com.[yourname].productname', is used to distinguish apps on the App Store.
  • 📝 Xcode's interface can be customized to focus on the editor and canvas, or to include navigators, inspectors, and debug areas based on the user's preference.
  • 🎨 The use of Swift UI is encouraged for beginners as it's Apple's direction for the future, offering an easier learning curve compared to UIKit and Storyboards.
  • 🔍 The inspector panel provides a visual way to adjust attributes of UI elements, which can also help in learning the corresponding code syntax.
  • 📱 Testing apps can be done on iOS simulators, which offer a variety of conditions to emulate real device scenarios, but ultimately testing on a real device is recommended.
  • 🛠️ Debugging in Xcode involves using breakpoints, stepping through code, and examining variables to identify and fix issues in the code.

Q & A

  • What is the purpose of the tutorial presented in the script?

    -The purpose of the tutorial is to teach students how to use Xcode to build apps, focusing on the context of building an app with a working knowledge that can be immediately applied.

  • Why should beginners avoid Xcode betas according to the tutorial?

    -Beginners should avoid Xcode betas because they contain bugs and are still undergoing changes, which can add unnecessary roadblocks to the learning process of building apps.

  • What is the recommended user interface technology for building apps in Xcode as per the tutorial?

    -The recommended user interface technology for building apps in Xcode is Swift UI, as it is the direction Apple is moving in and is considered easier for beginners to pick up.

  • How does the tutorial suggest managing different screen resolutions for images in an app?

    -The tutorial suggests using different sizes for images (1X, 2X, and 3X) and placing them in the asset catalog with appropriate names, so the app can choose the correct image size based on the user's device resolution.

  • What is the role of the 'entry point' file in an Xcode project?

    -The 'entry point' file is the first code that gets executed in an app. It is responsible for creating the initial screen or 'content view' of the app.

  • How can a developer preview their app in different states using Xcode?

    -Developers can use the 'preview' feature in Xcode to see their app in different states such as dark mode, light mode, different device orientations, and form factors.

  • What is the function of the 'Inspector' panel in Xcode?

    -The 'Inspector' panel in Xcode allows developers to view and modify the attributes of the selected component or file, providing a visual way to adjust properties without directly editing the code.

  • How can a developer run their app on an iOS simulator?

    -A developer can run their app on an iOS simulator by selecting the desired simulator device in Xcode, and then clicking the 'Play' button to build and launch the app within the simulator.

  • What is the significance of the 'toolbar' in Xcode's interface?

    -The 'toolbar' in Xcode's interface provides quick access to various functions such as hiding and showing panels, accessing the library of components and modifiers, and viewing the status of the project.

  • What are some benefits of enrolling in the Apple Developer Program mentioned in the tutorial?

    -Enrolling in the Apple Developer Program allows developers to submit unlimited apps to the App Store, invite beta testers, access analytics, and get support from Apple experts for troubleshooting.

  • How can a developer test their app on an actual device as described in the tutorial?

    -To test an app on an actual device, a developer needs to connect their iPhone to their computer using a USB cable, ensure the phone is trusted by the computer, and then select the device in Xcode to build and run the app.

  • What is the process of archiving an Xcode project and how does it help in deploying the app to the App Store?

    -Archiving an Xcode project prepares the package for distribution in the App Store. After archiving, the project appears in the organizer window, where developers can validate and then submit the build to App Store Connect for review and eventual release on the App Store.

  • How does the tutorial suggest using breakpoints for debugging in Xcode?

    -The tutorial suggests setting breakpoints by tapping on the line numbers in the code to pause execution at that point. Developers can then step through the code line by line to diagnose and fix issues.

  • What are some tips and tricks mentioned in the tutorial for efficient use of Xcode?

    -Some tips and tricks mentioned include using comments for documentation, navigating through the editor with breadcrumbs, using the back and forward arrows to switch between files, and using the search functionality to find text within the project or the entire project.

Outlines

00:00

📱 Introduction to Xcode Tutorial

The speaker, Chris, introduces the tutorial aimed at teaching students how to use Xcode for app development. He mentions that this tutorial will differ by integrating Xcode usage within the context of building an app, ensuring learners gain practical knowledge by the end. Chris advises installing Xcode from the Mac App Store, cautioning about its large file size and to avoid beta versions for stability. The tutorial then guides through launching Xcode and starting a new project, discussing platform options, and emphasizing the importance of a unique bundle identifier for App Store publishing.

05:03

🛠️ Navigating Xcode Interface and Project Structure

This paragraph delves into the Xcode interface, breaking it down into six main parts: Navigator, Editor, Canvas, Inspector, Debug area, and Toolbar. It explains the functionality of each component and how they can be hidden for more space. The speaker then discusses the project files, explaining the role of the project file in linking all files together and the importance of the root node in encapsulating all files. The entry point file of the app and its significance as the first executed code are also highlighted.

10:04

🌿 Exploring the Content View and Assets in Xcode

The tutorial continues by focusing on the content view, which represents the app's user interface. It describes how the entry point file creates a new screen and how additional views can be added. The assets section is explored, detailing where to store resources like app icons, colors, and images. The process of adding different sized image assets for various screen resolutions and how to reference them in code is explained. The paragraph concludes with a demonstration of adding an image asset and using it within the app.

15:09

🎨 Customizing UI Elements and Previewing Changes

This section teaches how to customize UI elements using code and the Inspector panel. It covers changing the image source, using modifiers to alter properties like color and scale, and updating text elements. The use of padding and the 'Content view previews' feature to test UI under different conditions is discussed. The paragraph also explains how to use the library to add new components and modifiers to the UI, emphasizing the ease of dragging and dropping elements to generate corresponding code.

20:17

🔧 Utilizing the Inspector Panel for Attribute Configuration

The Inspector panel's role in configuring attributes of selected components is highlighted. The paragraph explains how to modify properties like corner radius and padding directly through the Inspector, which updates the code in real-time. It also demonstrates how to explore available modifiers and add them to elements without memorizing code. The convenience of the attributes inspector for learning code representations and the efficiency of autocomplete in Xcode are also discussed.

25:22

📱 Simulating and Testing Apps with Xcode

The paragraph introduces the use of iOS simulators for testing apps under various conditions, such as different device orientations and memory states. It explains how to launch the simulator, interact with the app, and access additional simulation options. The tutorial also covers running apps on actual devices, detailing the process of connecting a device, trusting the computer, and deploying the app for testing. The limitations of simulators and the benefits of real-device testing are discussed.

30:23

🛑 Debugging Code with Xcode's Tools

Debugging is introduced as an essential part of app development, with Xcode's tools facilitating the process. The paragraph explains how to use breakpoints to pause execution and examine variables, step through code line by line, and navigate through breakpoints. It also covers how to set, disable, and remove breakpoints, and the importance of understanding code flow to diagnose issues effectively.

35:26

✍️ Enhancing Productivity with Xcode Tips and Tricks

The final paragraph offers productivity tips for using Xcode, starting with the use of comments to document code and logic. It suggests using comments to explain reasoning behind code decisions and to temporarily disable code lines. The paragraph also covers navigating the editor with breadcrumbs, using back and forward arrows, and collapsing code blocks for better readability. Searching through the project and accessing documentation quickly using the option key are additional tips provided to streamline the development process.

Mindmap

Keywords

💡Xcode

Xcode is an integrated development environment (IDE) developed by Apple for macOS, used for creating software for macOS, iOS, iPadOS, watchOS, and tvOS. In the video's context, Xcode is the central tool for teaching and building iOS apps, with the script detailing its installation and use for app development.

💡iOS Apps

iOS Apps refer to applications designed to run on Apple's iOS mobile operating system. The video's theme revolves around using Xcode to code and publish iOS apps, with the script providing a step-by-step guide for beginners to understand the process.

💡Swift UI

Swift UI is a user interface toolkit introduced by Apple that allows developers to design apps in a declarative manner. The script emphasizes learning Swift UI for building the user interface of iOS apps, as it is the future direction of Apple's UI framework.

💡Storyboard

A Storyboard in Xcode is a visual representation of the app's user interface and the transitions between different scenes. The script mentions Storyboard as an older UI framework compared to Swift UI, which is still in use but not recommended for new learners.

💡Bundle Identifier

A Bundle Identifier is a unique string that identifies an app across Apple's ecosystem. The script explains that the bundle identifier, usually in the format of 'com.[yourname].yourapp', is essential for publishing apps on the App Store.

💡App Store

The App Store is the digital distribution platform developed by Apple for iOS, iPadOS, and macOS where users can download and install apps. The video discusses the process of submitting apps to the App Store for distribution once they are developed using Xcode.

💡iOS Simulator

The iOS Simulator is a part of Xcode that allows developers to test their apps on virtual devices. The script describes using the iOS Simulator to preview and interact with the app during development before deploying it on actual devices.

💡Breakpoints

Breakpoints are a debugging feature in Xcode that allows developers to pause the execution of their code and inspect the state of the application. The script provides an example of setting a breakpoint to debug the app's functionality.

💡Debugging

Debugging is the process of finding and resolving defects or problems in a software program. The video script includes a section on debugging within Xcode, showcasing how to use the IDE's tools to identify and fix issues in the code.

💡Swift Programming Language

Swift is a powerful and intuitive programming language developed by Apple for macOS, iOS, watchOS, tvOS, and Linux. The script recommends learning Swift for new developers, as it is the recommended language for iOS app development in Xcode.

💡App Development Lifecycle

The App Development Lifecycle encompasses the stages a software application goes through from its conception to its retirement. The video script outlines the lifecycle in the context of using Xcode, from creating a project, coding, debugging, testing, to publishing the app on the App Store.

Highlights

Introduction to a tutorial on using Xcode for app development, taught by a team with experience in teaching thousands of students.

Emphasis on avoiding Xcode betas for beginners due to potential bugs and ongoing changes that can hinder the learning process.

Instructions on installing Xcode from the Mac App Store and the importance of having sufficient storage space.

Overview of creating a new project in Xcode, including selecting the appropriate options for an iOS app.

Explanation of project properties such as naming, team selection, organization identifier, and bundle identifier.

Discussion on choosing the user interface technology, with a recommendation for Swift UI over Storyboard for beginners.

Introduction to the Xcode interface, including the Navigator, Editor, Canvas, Inspector, and Debug area.

Description of the project file structure and the role of the .xcodeproj file in linking all project files.

Explanation of the App's entry point file and its role in creating the initial screen or 'ContentView'.

Details on the Assets folder, which houses resources like app icons, colors, and image assets.

Demonstration of adding and configuring images in different resolutions for various iPhone models.

Overview of the Editor and Canvas area, showing how code changes are reflected in real-time previews.

Introduction to the Inspector panel and its use for configuring attributes of selected UI components.

Explanation of the Toolbar's functions, including accessing the Library for additional views, components, and modifiers.

Instructions on running an app on an iOS Simulator, including selecting different devices and orientations.

Process for testing an app on a physical device, including connecting the device and selecting it within Xcode.

Discussion on the limitations of simulators and the importance of testing on real devices for accurate app behavior.

Overview of the Apple Developer Program, its benefits, and the process of submitting apps to the App Store.

Explanation of the archiving process in Xcode and the subsequent steps to deploy an app to the App Store.

Introduction to debugging in Xcode, including using breakpoints, the debug area, and stepping through code.

Tips and tricks for efficient coding in Xcode, such as using comments, navigating the editor, and accessing documentation.

Transcripts

play00:00

if you want to learn how to use xcode to build  apps you're in the right place my name is Chris  

play00:04

and our team has taught thousands of students how  to use xcode how to code and how to publish apps  

play00:10

now I have to tell you though this extra tutorial  is going to be a little different than the others  

play00:14

that you've seen instead of just giving you a  walkthrough I'm going to show you how to use  

play00:18

the xcode in the context of building an app so  that by the end of this tutorial you're going  

play00:23

to have working knowledge that you can put to use  right away all right enough talking let's Dive In  

play00:30

if you don't have xcode installed go ahead open  the Mac App Store type in xcode and click this  

play00:35

and install it now I will say that it's a pretty  big file size you're going to need even more space  

play00:41

than this just to get it installed and the second  thing is I would ignore these bad ratings xcode  

play00:47

is the official software that Apple gives us to  build iOS apps and even iOS professionals who  

play00:52

are developing apps day to day are using xcode  to do it also I would mention that if you're  

play00:59

just starting out avoid the xcode betas because  they contain bugs and their apple still changing  

play01:05

things and these things just add roadblocks to  you if you're trying to learn how to build apps  

play01:10

so stick to the releases in the App Store these  are the official public releases okay once xcode  

play01:16

is installed go ahead launch it and let's start  your new project all right xcode is launched and  

play01:21

you're going to see this welcome dialog if you  don't see this don't fear just go to file new  

play01:26

and choose project and uh what we're going  to do here uh you probably won't have these  

play01:31

because these are recent projects if this is your  first project you're going to hit create new xcode  

play01:36

project right here and it's going to give you  some options so up here notice you can develop  

play01:41

for different platforms I think when you install  xcode it's going to ask you if you want to install  

play01:46

things like for TV OS and watch OS if you're not  developing for those platforms you don't need to  

play01:52

install those things by default you're going to  have IOS and Mac OS and here you can create a  

play01:57

multi-platform app that means an app that can run  on let's say iPad iPhone you know different Apple  

play02:03

platforms what we're going to do here for the  purpose of this tutorial is to take you through  

play02:07

building an iOS in other words iPhone app so we're  going to go under the iOS tab here and we're going  

play02:14

to choose app right here so click next and let me  walk you through some of these project properties  

play02:20

so first of all you're going to give your project  a name uh I'm going to give this let's call this  

play02:26

xcode tutorial demo and for the team if you aren't  part of the Apple developer program then you  

play02:34

probably don't have anything to put here you might  have a personal team if you have an Apple account  

play02:39

but you don't have to worry too much about that  organization identifier combines with your product  

play02:45

name to create a unique bundle identifier now  this is going to be unique for every single app  

play02:51

that gets published in the App Store so usually it  goes like com Dot and then it might be your name  

play02:57

or your company name or your website whatever  it may be followed by dot followed by your prod  

play03:03

project name or product name so uh right here  put com dot your name or your website or company  

play03:10

uh and then the interface is basically what sort  of user interface technology do you want to use  

play03:16

to build your app by default it should say Swift  UI this is the direction that apple is moving in  

play03:22

all of the latest things that get announced is  regarding Swift UI storyboard is sort of their  

play03:28

older UI framework that's as of this recording  still in use a lot out there but Swift UI is maybe  

play03:37

about as of this recording maybe three years old  but it is the future as Apple's sees so I would  

play03:43

recommend that you learn Swift UI especially  as a beginner because it's much easier to pick  

play03:48

up you can always go back and learn UI kit and  storyboards language definitely choose Swift  

play03:54

or I don't even have the option okay if you choose  storyboard you have the option to select Objective  

play04:00

C which is the I guess you could call the original  programming language used since then Apple has  

play04:06

introduced the Swift programming language which is  the recommended option uh to learn these days so  

play04:13

I would definitely select Swift whether you are  using Swift UI or storyboards and then I would  

play04:20

uncheck any of these options if you have any of  these checked because we don't need these things  

play04:26

right now it's just going to complicate things and  as you grow as an app developer you'll learn more  

play04:31

about these options so let's go ahead and hit next  and create our brand new project it's going to ask  

play04:37

you where to save it this you can leave unchecked  as well because again it's not something that  

play04:42

we're going to cover in this tutorial if this is  your first time creating an app I would recommend  

play04:47

that you create a dedicated place for all of  your apps for me I'm just going to save this  

play04:52

on my desktop hit create and it's going to give  it a word and let me just expand this window and  

play05:02

then we're going to go through all of our new  files because we're going to do this tutorial  

play05:06

in the context of building an app all right after  you give a few moments for your xcode to load up  

play05:12

the new project you're going to see a giant iPhone  on your screen here now before we dive into this  

play05:18

project and tell you what all of this means it is  a little overwhelming at first glance we can split  

play05:24

this interface up into six distinct Parts on your  left hand side here this is your Navigator this  

play05:30

is where you're going to look at the different  files of your project this part right here where  

play05:34

you edit the code is called the editor and it's  where you're going to write your code this is the  

play05:40

canvas where you can preview what code you've  written like this is what is being generated  

play05:45

from what you write in the editor and then to  the right of the canvas we have the inspector  

play05:51

area notice that there are a couple of tabs here  in the inspector and also notice that we have a  

play05:56

couple of tabs up here uh for The Navigators as  well because you can navigate between different  

play06:01

things in your project now the inspector area is  for looking at details in your editor more closely  

play06:08

we'll dive deeper into each of these sections but  right now let's give you an overview across the  

play06:14

top you have your toolbar and this is where you  can see the status of what is happening to your  

play06:18

project whether you are building it to run where  you are running it because you can select to run  

play06:24

it on different devices and things like that down  here this is hidden but you can bring this up to  

play06:32

show the debug area and this is where you're going  to troubleshoot some of the errors or code that's  

play06:36

happening with your project but you can hide  that for now so that's there's a little button  

play06:40

there for that in order to create more space for  yourself you can hide these different panes as  

play06:45

well so for example this button right here hides  all of your inspectors this button up here hides  

play06:51

your Navigators so now you only have your editor  and canvas where you'll be spending the majority  

play06:56

of your time and if you're used to just writing  code and not really looking at your preview you  

play07:01

can even turn this off by tapping on this button  and then saying show editor only and you're going  

play07:07

to get a screen full of code so those are the  six main areas you'll be spending your time in  

play07:12

this is the code editor we can click this button  and choose canvas to bring that back and then we  

play07:17

can tap on this button to bring the inspectors  back which allow us to dive into elements inside  

play07:23

our editor we can tap on this button to bring  back our Navigators and this button down here  

play07:29

to bring up our debug area now that you know the  main areas of xcode let's dive into your project  

play07:35

files so we can explain what an xcode project  is made up of so first let's ask the question  

play07:41

what is an xcode project we created a brand new  project here and we were asked where to save it  

play07:47

so let's pull up that location on disk and take  a look at what files I've created so first of all  

play07:52

there's a folder with all of your project files  inside and notice how these map to what you see  

play08:00

here in the file Navigator and then there's also  this xcode proj extension this is your project  

play08:08

file that links all of these files together into a  single package and so when you're sending someone  

play08:15

an xcode project you don't just send this file you  also need all of the files in this folder together  

play08:21

so usually I'll just zip it up but anyways these  are your files representing your new xcode project  

play08:28

and then you can look at them through here your  file Navigator if you don't see these files you  

play08:34

might be on a different tab so make sure you are  on this first file Navigator tab let's go through  

play08:40

these files so you can understand what your  project consists of so if you click on this first  

play08:45

root node up here in fact you can collapse it you  can see this encapsulates all of your files which  

play08:51

is representative of this right here so if you  click on that the editor area is going to change  

play08:58

and these are all of the configuration details for  your project this is where you can figure things  

play09:03

like version numbers and orientations and things  like that there is a lot that you can do here but  

play09:09

we're not going to dive into that for now you  don't need to know any of that just know if you  

play09:13

need to configure something with your project  or enable a certain capability let's say in-app  

play09:19

purchase or something this is where you would go  next we have that folder that houses all of our  

play09:24

files right we saw that in the font system if you  expand that we have this this file is going to be  

play09:32

your product name and this is the entry point for  your app this is the code that gets executed first  

play09:39

so what I want you to notice in here is we're  going to gloss over a lot of this code if you  

play09:46

want to dive deeper and understand what these  things mean I definitely urge you to check our  

play09:52

app beginner challenge where we have 10 lessons  to spend together and it's on YouTube and I will  

play09:58

explain in detail what all these things are for  now I want you to notice that this content view  

play10:04

right here what it's doing is it's creating a  brand new content View and if you look we have a  

play10:10

Content view file up here so let's click on that  and this is basically your content view you can  

play10:16

see a visual representation of it here and right  here you'll see that it is declared as content  

play10:23

View and this is the code that generates all of  this UI and all these elements that you see here  

play10:33

so if we go back to this entry point file what  is it doing it's creating a new content view so  

play10:40

essentially it's creating a new screen and that  screen is content View and that screen is is  

play10:46

dictated by this code right here that's what the  screen looks like so hopefully you get a sense now  

play10:52

of the flow of the app right you have the entry  point it's creating a brand new screen and that  

play10:58

screen's called content View and that's what you  have right here and this is this code right here  

play11:02

is what represents the content view UI now you're  not limited to one screen as you know so you can  

play11:10

always right click and choose new file and you're  going to be able to add a new view and we're not  

play11:18

going to touch into that today definitely check  out the app beginner series like I mentioned  

play11:23

in order to learn more about creating multiple  screens and things like that and how to link them  

play11:27

together and navigate between them for now let's  move on to the other files in our project we have  

play11:33

this assets right here here you're going to store  the resources for your app so what do I mean by  

play11:38

resources I mean things like your app icon you can  simply drag and drop an image in here colors for  

play11:45

your app so here you have a default accent color  for your app but you can Define your own colors  

play11:51

so maybe you have three or four colors that you  reuse throughout your entire app so this is where  

play11:57

you would declare those colors and then you could  also let's just click that you could say this is  

play12:03

you know like button color or something like that  maybe you heard a little more descriptive than me  

play12:08

but you would basically Define perhaps a color for  all your buttons and you would then choose a color  

play12:14

for light mode or any mode and you can define a  color for dark mode so if the user is using dark  

play12:20

mode it's automatically going to choose this color  for your buttons and when you're writing code in  

play12:25

here you can reference that color by this name  right here so you can also create images like  

play12:32

a new image set so when we do that let's say we  have an image that we want to use in our app so  

play12:38

I'm going to name this image plant like that  notice that for plant I have one X2 X and 3X  

play12:47

now these are different sizes for my image because  there are different screen resolutions for iPhone  

play12:52

so essentially you're going to have the same  image asset but in three different sizes one  

play12:59

that's double the size and one that's triple the  size you're going to drag all three versions into  

play13:04

here and when the app runs it's going to choose  the appropriate image size to use based on the  

play13:10

user's device resolution alright so let's try  it out I actually have an image that I prepared  

play13:16

um for us to take a look at and that's just this  this plant right here so I'm going to drag it into  

play13:21

here it's going to automatically create that asset  name for me and it's going to treat this as 1X now  

play13:29

if I had the 2X and 3X versions I would drag it  in here as well and I would name it the same thing  

play13:34

but it would be named it would essentially be like  something like this so let me just duplicate this  

play13:39

file and show you how the file name would go  it'd be like the at 2X and then if I drag it  

play13:48

in here I could put it in the 2x now obviously  I just duplicated it so it's both actually the  

play13:53

same size but that's how you would name your three  different sizes and the other one would be at 3x  

play14:00

and you drag it right there so if I were to use  this image inside my app I would reference it by  

play14:07

this so we're going to try that in just a moment  when we get to talking about the editor area but  

play14:13

for now let's finish off talking about the rest  of the files in our project we have this last  

play14:18

folder called preview content and here we have  another resource library and this is where you  

play14:23

can Define your assets for previewing specifically  this is for when you're building your app and you  

play14:32

are seeing these previews perhaps you're not able  to fully visualize what your UI will look like  

play14:39

unless you have some sample images so that is  where you would put your test or sample or demo  

play14:44

assets that's where you put that there in preview  assets all right now that you're familiar with all  

play14:50

the files in your project and navigating through  them using the file Navigator let's move on to the  

play14:55

editor and canvas area as you can probably guess  by now the editor area including the canvas here  

play15:02

changes depending on what you select so that  you can edit your selected file if I select  

play15:08

this project file it's going to let me edit the  project configuration details if I select let's  

play15:16

say the resource Library it's going to let me  edit those things and when I select this is a  

play15:21

pure code file it's only code but when I have a  view it gives me a code plus canvas preview type  

play15:28

of editor layout here so there's actually a lot  of cool productivity things with the editor here  

play15:34

such as being able to jump to different parts of  the code if you have a really long code file you  

play15:41

can adjust the sizing of this and up here along  this bar you can see that we have multiple tabs  

play15:47

so you can switch files easily you also have  these arrows here which are very easily missed  

play15:53

that allow you to jump backwards and forwards kind  of like a browser like a chrome or a safari or  

play15:59

something like that you also have the ability to  open up side by side files so this window can be  

play16:06

showing one code file while this one shows another  and because sometimes you want to compare or  

play16:12

maybe look at two files at once you can rearrange  these windows you can even have four depending on  

play16:17

your screen real estate but we can get deeper  into those tips and tricks at the end of this  

play16:23

tutorial for now I want to show you how you can  write code in the code Editor to build your user  

play16:29

interface that you can preview here so what I want  to bring your attention to is this block of code  

play16:35

right here these few lines of code represent what  you see here so let's break it down a little bit  

play16:41

you see this v stack right here that stands for  vertical stack and it basically allows you to put  

play16:47

multiple things on top of each other if you look  at the vertical stack let me just collapse this  

play16:53

code a little bit so you can see you write v stack  and then you have an opening bracket and a closing  

play17:01

bracket and whatever you put between those two  brackets are the elements that you're stacking  

play17:06

on top of each other so if you take a look at the  preview right here you have a little image of a  

play17:11

globe and you have this hello world label here  those two things are on top of each other so let  

play17:17

me open up the contents of the v-stack and you'll  see that we have an image element that's this  

play17:26

globe right here and we have the text hello world  that's this label right here and because both of  

play17:32

those two things are inside the v-stack they're  stacked on top of each other and furthermore the  

play17:37

image is on top of the text so you can see how  writing this code is very intuitive to be able to  

play17:45

imagine what this UI would look like so now let's  dive a little deeper into the image element you  

play17:52

have an image and this part inside the brackets is  specifying what image to show now Globe is an icon  

play18:00

that comes pre-installed in fact we can change  this globe to another pre-installed icon these  

play18:07

icons are called SF symbols and they come with  iOS these are the standard symbols that iOS users  

play18:15

are used to seeing on iPads and iPhones and you  can download this SF symbols beta app and I know  

play18:22

in the beginning of this video I told you not to  download any betas but there is no public release  

play18:27

of this it's still in beta let me launch it for  you because I have it right here and I'll show you  

play18:33

what this looks like so this is just an easy way  to grab different icons to use in your app so you  

play18:40

don't have to you don't have to download anything  or add any images so let's for example pick this  

play18:47

one the name of it is scribble dot variable so  I'm just going to go ahead and copy the name  

play18:53

and then I'm going to replace  that in here with globe and let's

play19:01

it's it's doing something and then you'll see it  update here in the preview and you see that is  

play19:05

exactly the symbol that we have now what are these  let me just open this up a little bit so we see  

play19:12

these in a line now image scale large it modifies  the image element so this is indicating what scale  

play19:21

should we show the image this is another modifier  it changes the color of the image element so for  

play19:28

example I can change instead of the accent  color I can change green but before I do that  

play19:33

where have you heard accent color before that's  right inside our resource Library accent color  

play19:39

right because I haven't specified any color there  it's using the default accent color which is blue  

play19:46

so we can change the accent color or you could  just put green there or perhaps red and change  

play19:54

it to Red next below that we have a text element  which is essentially just a label you can't really  

play20:00

do anything with it but it displays text so  we have hello world or we can change that text

play20:08

the quote inside here is  the text that is displayed

play20:17

so it's really as simple as that furthermore if  you want to modify this text element maybe you  

play20:23

want to make it bold let's add a bold modifier  to the text and now you can see that it's bold  

play20:29

so these two elements are contained within the  v-stack I can collapse the v-stack like that  

play20:35

and then you can see what is this this is a  modifier for the v-stack this padding will add  

play20:45

padding along all four sides of the v-stack  itself if I remove this modifier you can  

play20:53

visually see anything because the padding  is sort of invisible here but if it filled  

play20:58

if we had a line of text that went all  the way from the left to the right if  

play21:02

I didn't have the padding modifier it  would touch the two edges of the screen  

play21:06

if I added the padding modifier back then we would  get the left and the right margin now let's take  

play21:11

a look at using the image that we had added to  the asset catalog here this this asset monstera  

play21:20

deliciosa I don't even know if I'm pronouncing  that correctly so I apologize if I mess that up

play21:29

it's a little ciosa and then for the  image we have system name but that's  

play21:34

not what we use for our own added  image that's what we use for the  

play21:38

SF symbols that I just showed you so  we're going to get rid of all of that  

play21:42

and in in between the two brackets here we're  just going to put two quotes and then we're  

play21:47

going to put the name of the asset that we added  so going back here so just taking a look at that  

play21:52

name all lowercase with a dash in between right  that's exactly how we have to spell it right here

play22:03

all right so that appears right  there and if we wanted to let's say  

play22:10

give it rounded corners we can use another  modifier called Corner radius and it might  

play22:17

be a little hard for you to remember all of these  different modifiers but over time as you use them  

play22:22

you're going to get to know them and you're just  going to remember and I will show you coming up  

play22:27

when we look at the inspector tab how you can add  these modifiers without actually remembering them  

play22:33

okay so what I do here I added this modifier  for the image element and I put 20. that's the I  

play22:39

guess the degree of rounding that I want and then  furthermore I might say like hey this text is too  

play22:46

close to the image perhaps I will add another  modifier to this text and I would add padding  

play22:53

and you can see that it's going to add padding on  all four sides so then if we move a little farther  

play22:58

down in this code file you'll see that it says  content view previews right previews right here  

play23:05

this is the little bit of code that is generating  what you see in the preview right you can see here  

play23:13

it's creating a new content view which is what  this is right the cool thing about the preview  

play23:19

is that we can actually put this in different  states we can see this UI that we've built in  

play23:25

let's say a dark mode or an iPad or a smaller  form factor or maybe landscape orientation all  

play23:31

those things you can do by adding modifiers on  the preview here but there's also an easier way  

play23:37

to do that we've have buttons down here now where  you can just click and do those things so if you  

play23:43

click on variants for example you can change the  color scheme or you can see the dark mode version  

play23:49

and the light mode version perhaps you'd like  to look at orientation differences and how your  

play23:55

UI would be affected and how it would look in  those orientations you could do that you can do  

play24:01

type like different size types and there's there's  a lot of different things that you can do here  

play24:08

okay so let's go back to our initial view here  so I hope that gives you an overview of the code  

play24:14

editor and the preview and how editing the code in  here affects what you see in the preview now there  

play24:20

are like I said a lot more intricacies with the  code Editor to make writing code easier as well  

play24:27

as with the preview but we'll save those for the  tips and tricks section at the end of this video  

play24:32

for now let's move on to explore the right side of  the screen the inspector panel the inspector panel  

play24:38

all the way on the right hand side has different  tabs as well that give you various information  

play24:44

and configuration for whatever you select either  within the editor or files so let me give you a  

play24:54

demonstration for example we were talking about  the v-stack if I put my cursor on the v-stack  

play24:59

you'll see that the inspector panel changed and  I went into this panel right here for some quick  

play25:04

help this one gives me a summary about what the  v-stack does um and some sample code about how  

play25:10

to use it and furthermore I can click on this link  to open up the developer documentation which gives  

play25:16

me more information about the v-stack and uh how  to use it and all all that sort of stuff so that's  

play25:22

very very handy if I select let's say the image  again this changes to the image component and  

play25:29

how to use it and all about it super helpful if  I select a file for example let's say I select  

play25:36

the asset library and I select let's say accent  color and then I select this if we switch over  

play25:43

to a different tab so this last tab here in  the inspector panel is called the attributes  

play25:49

inspector I can configure different attributes  about what I've selected in the editor here so  

play25:55

for this accent color I could select what devices  I want it to be available on does it appear on  

play26:01

light dark or any and then actually I can I can  choose the actual color for example for images  

play26:08

for example I can select an image and you can see  there's all these different attributes that I can  

play26:13

set in this attributes inspector if I select a  file for example I can go over to the identity  

play26:21

and type inspector which gives me information  about the file itself such as where it's located  

play26:27

and is it part of this project like right here  now this is where it gets really interesting if  

play26:35

I go to the attributes inspector and I highlight  a component here you can see that I can configure  

play26:41

different things for that image component you  know how we were writing code right here for  

play26:48

Corner radius well I'm not limited to just writing  code I can actually modify things here for example  

play26:56

you can see here that I have a corner radius it  20 and this is because it's reading the code that  

play27:03

I've written so I can see it here if I wanted to  change this to let's say 10 I can either modify  

play27:08

the number here or I can change the attribute  to 10 right there and you'll see it reflected  

play27:13

in the preview and also the code and if I'm not  sure about what modifiers are available to me  

play27:20

for the image component I can come down here I can  then I can take a look at the different available  

play27:26

modifiers I can type in one to filter for example  if I want to make this image smaller I might add  

play27:33

a resizable modifier actually I might not need to  do that through here because I can just modify the  

play27:41

size so for example if I let's say change the  width to let me just type this out 200 and um

play27:55

300 or something like that then I can change  that right there now you'll notice that it  

play28:00

just sort of cropped it it didn't actually change  the image size if I wanted to actually change the  

play28:05

size of the image I would need to add a modifier  here called resizable like that and then you'll  

play28:12

see that now it actually changes the size of the  image rather than just cropping it furthermore do  

play28:18

you know how in the text element here we had  added padding right so there's this padding  

play28:25

modifier right here if I got rid of this padding  you'll see that it goes back to being too close  

play28:31

to the image but what I can do is I can just  add top padding so I can select that top and  

play28:38

furthermore I can either leave it to the default  or I can change the amount of padding that I want  

play28:46

and then you can see it reflected here in the code  so using this inspector to add and edit modifiers  

play28:54

for your element is also a very good way to learn  what the code representation for that would be and  

play29:01

if you continue building apps and working inside  xcode there come to be a point where it's faster  

play29:06

for you to just type it out rather than going over  here into the attributes inspector to configure  

play29:12

things because you'll notice that as I'm typing  things there's something called autocomplete  

play29:19

right typing that out I just had to type dot Cor  and then enter and then 10. and just typing that  

play29:27

out takes it's way faster than clicking this  and then coming here and selecting things so  

play29:32

there'll come a time if you keep at it where  you just remember these modifiers and you can  

play29:37

just type everything out in code and I want to  point out something else as well with this text  

play29:41

element you can see different types of attributes  that you can configure versus the image element  

play29:46

so for text obviously you can configure the font  the weight the alignment and the line limits and  

play29:52

things like that with the image you get different  things so that's the important thing to know about  

play29:57

the inspector panel let's move on to this strip  along the top called the toolbar now there are  

play30:02

a few remarkable things about the toolbar you know  how I said if you highlight a component right here  

play30:07

and you go over to the attributes inspector  you can configure different properties for it  

play30:11

well what if you don't know what components are  available to you in Swift UI to build your user  

play30:17

interface with well that's where the library comes  in handy if you click on this little plus icon in  

play30:22

your xcode toolbar that brings up the library and  there are few different tabs here but we'll go  

play30:27

through the first tab because that shows all of  the different views and components that you can  

play30:33

add to your user interface and the best thing is  that you can either double click this or you can  

play30:37

drag and literally drop it into your code editor  and then you can see what the resulting code would  

play30:43

be so this is what a button looks like you can  see here it's green and it's green because in  

play30:49

our asset Library we change the accent color to  be a default of green so actually I don't really  

play30:55

like that so why don't we go ahead and just  change that to a the default blue for example  

play31:03

so we'll go back to the content view you'll  see that the button is blue furthermore this  

play31:08

text inside the button here you can change that  to say you know tap on me and then inside here  

play31:15

action you see this is uh opening bracket  this is a closing bracket in between these  

play31:21

two brackets you would put the code that you  want to run when the user Taps on the button  

play31:28

let's open up the library again for example if  you know what you're looking for you can just  

play31:33

filter you can add a toggle if you don't know what  you're looking for you don't know what this is you  

play31:38

can always look at this documentation on the right  hand side again you just drag it and drop it and  

play31:45

let's put that on a new line and you can see there  is your toggle switch now the library doesn't only  

play31:53

have views that you can add also has a collection  of modifiers see that's what what the second tab  

play31:59

is so that also answers the question what if you  don't know what modifications you can do to those  

play32:05

elements again you can try to drag and drop these  different things see their blur effects accent  

play32:12

colors brightness clip shapes like all sorts of  things you can explore here's one that we just  

play32:18

used Corner radius gives you some documentation  about that you can have different code Snippets  

play32:24

like if you can't remember how to write something  in the Swift programming language you can look it  

play32:31

up here so let's say an if statement this allows  you to specify different branches of code like  

play32:37

if this is true then do this if it's not true  like if it's false then do that that's what an  

play32:43

if statement is and then you can just drag this  and drop it in here and you can look at what that  

play32:49

Swift Code looks like so this is a great way of  actually learning as well because you can see  

play32:54

what the code representation of a button is you  can see what a code representation of a toggle is  

play32:59

and you can don't forget you can put your cursor  on that and then you can configure that toggle or  

play33:05

button over here in the attributes inspector now  returning to the library for a second we also have  

play33:12

let's get rid of this uh you also have easy access  to all of the images you've added to your resource  

play33:19

libraries you also have all of the custom colors  that you have specified in your resource library  

play33:25

in this last one surprise are the symbols so you  don't even need that SF symbols app although that  

play33:35

does give you an easier way to browse because all  the icons are broken up into categories but this  

play33:41

is another way here's the one we use for scribble  variable so the library is very very useful  

play33:48

also in the xcode toolbar are the buttons here  to hide and show the file Navigator and the  

play33:55

inspector panels respectively another thing I'll  draw your attention to is this status right here  

play34:02

this tells you what xcode is doing behind the  scenes sometimes when you just launched xcode  

play34:07

and you're booting up your project or you're  starting a new project you'll see you're going  

play34:12

to be waiting you're going to see a progress  indicator and it's going to tell you what's  

play34:16

happening behind the scenes also you'll notice  that there's your product name right here and that  

play34:22

might seem a little redundant because nothing  happens but it's because sometimes for larger  

play34:27

projects you have what's called an xcode workspace  and you might have multiple xcode projects inside  

play34:34

a single workspace but more importantly for you  right now is probably this area right here so  

play34:41

this indicates what project you're looking at and  this indicates what simulator you want to use now  

play34:49

before we get into simulators let me first mention  about this preview right here so this preview is a  

play34:56

great way to take a look at what your code looks  like visually you can even interact with this see  

play35:03

I can tap on this I can toggle the switch right  like that now a preview is great for seeing how  

play35:10

this single view or screen looks like however  if you want to go through the flow of your  

play35:17

multi-screened app you'd want to launch your app  either on your phone on your actual device or on  

play35:25

an iOS simulator which is what you are selecting  up here so a simulator is just exactly what it  

play35:32

sounds it's going to be a representation of your  app on a virtual device that appears on your  

play35:38

screen so let's let's show you an example of this  now just a note before we do this after I show you  

play35:45

the iOS simulator I will show you how to run it on  an actual device okay so let's go ahead and select  

play35:51

iPhone 14 pro and look at this play button right  here right we are going to tap on this button  

play35:58

which will build the project and it's going to you  can see the status part is is doing stuff xcode's  

play36:05

performing all of these operations behind the  scenes and it's getting ready to launch your app  

play36:11

inside a virtual simulator which it'll take some  time if this is the first time you're launching  

play36:15

the iOS simulator give it some time it's going  to bring it up on the screen but you'll notice  

play36:19

there's a stop Button as well so if you want to  cancel the operation just go ahead and hit stop  

play36:24

all right so my iOS simulator has launched here  it is I can tap on this and drag it around I can  

play36:32

interact with it if I had multiple screens I could  navigate and use my app there are different things  

play36:39

you can do here such as rotate the orientation or  change the orientation I mean you can also take a  

play36:47

screenshot you can even take a video actually  in one of these menu options up here you can  

play36:52

hit the home to go back to the home screen and you  know this this is really a simulator you can have  

play37:00

different contacts you can have different apps in  here but this is primarily to test your app under  

play37:07

different conditions if you dive into the menu  you can simulate a lot of different scenarios that  

play37:15

would happen with a real device so you can check  out all the menu options here but what I want to

play37:23

um right here so we can simulate a fall you can  play around with face ID you can yeah there's a  

play37:29

lot of different things you can do in here you can  even put in a custom location so you can simulate  

play37:35

as if the user were at whatever location that you  would want if you're building let's say a Maps  

play37:42

app or something like that under the debug menu  you can simulate if the device is low on memory  

play37:50

you know there's a lot you can do here and that's  why the simulator is so helpful however there is  

play37:56

a limit with what you can do on the simulator it  is not perfect the best thing would be to actually  

play38:02

test it on a real device but before we do that one  more thing I want to mention about the simulator  

play38:07

is that you can have multiple simulators open at  the same time so you can hit stop you can pick a  

play38:12

different one like let's say iPad or iPad Air and  you can launch that and you can have two cylinders  

play38:19

up and running at the same time another thing  you can do with the simulator is you can reset  

play38:24

it so you can either restart the device or you  can completely erase content and settings which  

play38:29

would be kind of simulate a brand new phone type  of feeling okay so if you want to run your app on  

play38:37

an actual device what would you do well you would  need an iPhone cable and you would need to plug  

play38:43

your device into your computer or your laptop  so I'm going to plug mine in what you're going  

play38:49

to see on your phone if it recognizes your phone  at all is you're going to see a menu that says do  

play38:56

you trust this computer if this is the first  time you've plugged in your phone it's going  

play39:00

to say that and you're going to say trust you're  going to enter in your passcode and here you can  

play39:05

see that it's preparing my phone for development  and then what you should see is your device here  

play39:13

now for me I haven't updated my iOS version on  my phone yet so it's telling me that I I'm on  

play39:20

15.6.1 and because this is the new xcode 14 it's  running things on iOS 16. it can't put this app  

play39:29

on my device until I update to iOS 16 on my device  however if in theory we didn't have this problem  

play39:37

my phone would show up right here on the list and  I'd be able to select it like that just like that  

play39:43

and I would be able to hit this button to run and  it would actually launch the phone just like you  

play39:48

saw it launched in the simulator except it would  launch it on my phone and I would get to interact  

play39:52

with it so that's a really cool way to build  something and very easily put it on your device  

play39:58

and go around and show people now the ability  to do this to put your app on your own device is  

play40:03

for testing only so in about 14 days I forget if  it's 7 or 14 days it will start to expire and it's  

play40:12

going to warn you about that and that that point  in time you either plug it in again and reinstall  

play40:19

the app on your device again to get another 14  days or if you want a more permanent solution you  

play40:26

need to sign up for the Apple developer program  which is a paid program you can Google it which  

play40:33

would then give you the ability to install your  app on your devices for the long term as well as  

play40:39

to publish it onto the App Store as many apps that  you want alright so now you have a real sense of  

play40:44

building your app you know how to preview your  screen using previews you know how to test your  

play40:49

app on the iOS simulator you know how to test your  app on a real device so how do you actually submit  

play40:56

your app into the App Store and get it approved  so that it can be used by millions of people let's  

play41:01

talk a little bit more about that Apple developer  program I just mentioned so if we pull up the  

play41:06

Apple page on the Apple developer program it's  about a hundred dollars USD to enroll per year  

play41:13

and that allows you to submit unlimited apps into  the App Store it allows you to invite beta testers  

play41:21

to your app and they can you can make it available  for them to install here it says you can put it on  

play41:27

the App Store and distribute your apps you can get  analytics about your sales about like Impressions  

play41:33

on your app store listing conversions on the you  know clicking the download button and things like  

play41:38

that and you get a couple of credits to connect  with apple experts to troubleshoot your issue so  

play41:44

once you enroll in this apple developer program  you have access to What's called the App Store  

play41:49

connect and as it sounds it's basically your  dashboard for all things that have to do with  

play41:54

the App Store now these are some of the apps that  they're not currently all on the App Store however  

play42:01

I want to show you an example of how you would  list your app and then how you would use xcode to  

play42:10

deploy your app into the App Store and deploy is  just a fancy word of saying sending or installing  

play42:16

so let's take this for example I'm going to click  into this existing app store listing if you were  

play42:21

to create a brand new app you'd click this plus  button to create a new app store listing and in  

play42:27

here you would configure all things about your  app such as the screenshots app information  

play42:33

pricing availability you can manage ratings and  reviews you can configure in-app purchases and  

play42:39

subscriptions and promotions and things like  that and this is where you'd also put your app  

play42:43

store description now once you've configured all  of this app store listing information what you'd  

play42:49

want to do is it depends what platforms you have  but for iOS come into here and you would specify a  

play42:55

new release so we are at 1.0.3 and here you can  talk about what's changed in this version you  

play43:02

can add screenshots for this specific version  write the description all of this metadata is  

play43:08

associated with that version and then when it  comes down to here build this is where you are  

play43:15

going to specify your xcode project so how do  you send your xcode project from xcode to App  

play43:23

Store connect specifically linking it to this  app store listing so you might think that oh I  

play43:29

need to zip up all my files here you know all  these project files that I told you about and  

play43:34

then upload it here but no it's actually easier  than that so you go into xcode and what you want  

play43:39

to do once you've tested your project it's ready  to launch into the App Store you go into product  

play43:44

right here and you choose archive what's gonna  I'm not going to do it right now well actually  

play43:50

okay let's do it right now so I'm going to  hit archive and it's gonna yeah it's not ready  

play43:56

it's not ready for archiving right now but you're  basically preparing that package for distribution  

play44:04

in the app store that's what archiving does  so if I were to successfully archive this  

play44:10

project then it would pop open this window this  organizer window and I would see my app here  

play44:19

and if I I don't even have it here  because we didn't set this project up  

play44:24

um and we didn't connect it to the team that is  associated with this app store connect account  

play44:32

otherwise my app listing would automatically  appear here but anyhow let's pretend that this is  

play44:41

the app under archives right here I would see the  archive that I just made right and I would also  

play44:48

give it a specific version number right so you  can put it right here version two version 1.0.5 or  

play44:56

whatever it may be and then you would go product  archive and then it would appear in this organizer  

play45:02

window and you'd be able to select it and then you  would be able to hit a button it would run some a  

play45:09

couple of checks to make sure it's ready for the  App Store and then it would send that archive  

play45:14

here and it will know to send it to the app to  the specific version and then it will show up  

play45:20

here and then once you have that build right here  put in any information that you would want the App  

play45:27

Store reviewer to know as they review your app  for App Store certification and then you just  

play45:34

hit the release button you can also specify when  to release it you can manually release it after  

play45:39

it gets approved or you can automatically release  the app after the reviewer approves it and that's  

play45:45

pretty much how you publish an app onto the  App Store now this is the end goal of all of  

play45:51

us developers right but before you even get there  in the process of building your app you're going  

play45:56

to run into obstacles and roadblocks and there's  going to be code that doesn't work the way that  

play46:02

you intended it to work how do you troubleshoot  these issues and how do you resolve them let's  

play46:07

take a quick look at debugging using the tools  in xcode which is just the fancy way of saying  

play46:12

fixing your bugs and resolving your issues okay  so we're back inside xcode you'll notice that  

play46:17

when we launched this project in an iOS simulator  that this tray this debug area popped up now I  

play46:27

mentioned you can tap on this button to open this  area but it popped open automatically because  

play46:32

there there was diagnostic information to display  furthermore there are two panels here and that  

play46:39

is controlled by these two buttons so this one  hides the right one this one hides the left one  

play46:44

or shows it and this trash can icon clears this  sort of log right here so in order to debug your  

play46:53

code oftentimes it's just a process of trying  to figure out where the problem is happening  

play47:01

and then walking through step by step as the code  is being executed and looking at if everything  

play47:08

is as you expect so once you can identify where  things are going wrong then you can see what the  

play47:15

issue is and fix it so here are some methods to  display information and then also to walk through  

play47:23

the code line by line let's start by removing  this toggle element and we'll use the button  

play47:30

right now so let's say when the button is tapped  on we are going to print something out into the  

play47:37

uh the console window here so let's go ahead  and launch the simulator again in an uh on an  

play47:45

iPhone 14. so this is a subsequent launch so it  should be a lot faster all right so when I tap  

play47:52

on a button you can see that each time I tap on it  it runs the code inside here and it prints it out  

play48:00

right furthermore we can set What's called the  break point inside xcode so you see these line  

play48:05

numbers if I tap on line 14 I add this blue marker  here when the code is running if it gets to that  

play48:13

line where I have this blue marker it's going  to pause the execution and then I can go peek  

play48:19

at different things to see what's happening so  let's try that out I've set a break point on this  

play48:25

and if I tap on this now it reaches here and  it highlights this line in green because that's  

play48:31

where the execution it's about to execute that  line of code it hasn't yet because it sees I've  

play48:38

set a break point it stops there and then at this  point I can peek at different things I can examine  

play48:43

different variables or components or whatever  the case may be furthermore once the execution  

play48:50

has paused on one of my breakpoints I can start  stepping through the code line by line and that  

play48:55

is controlled by these buttons here so this button  here is just continue the program execution which  

play49:01

is basically like continue executing from this  breakpoint so then it's going to run this line and  

play49:05

keep going or this one right here which is step  over which is then going to continue to the next  

play49:12

line of code like that you see what just happened  it executed this line and then it moved to the  

play49:18

next line and it stopped again so this way you can  control the flow and you can slowly diagnose what  

play49:25

is going on now as a beginner sometimes you're  going to accidentally set a breakpoint and you're  

play49:29

not going to know how to turn it off so here's  how you get a breakpoint away you can either tap  

play49:35

on it to disable it or you can completely drag  it off the line and get rid of it you can tap  

play49:42

it off you tap it on you drag it off furthermore  if you have multiple break points let's say here  

play49:50

and here you can go over to the Navigator  there's a breakpoint navigator it'll tell  

play49:55

you exactly where you've set break points in your  project it even shows you which ones are disabled  

play50:02

okay so I think that's a really good starter  primer to debugging an xcode there's obviously  

play50:08

a lot more that you can do once your code gets  more complex but it's a little hard to demonstrate  

play50:13

those things with this simple project again check  out the beginner app series that we have here on  

play50:20

the code with Chris YouTube channel and it will  talk about all of those things what I want to  

play50:24

show you next are some cool tips and tricks to  make using xcode a lot more fun and efficient for  

play50:29

you let's start off with the basic thing which is  comments Now comments are basically little notes  

play50:35

that you can leave yourself without affecting the  code so it is just documentation or comments for  

play50:42

yourself to understand what's going on for example  up here on top of the file you'll see these two  

play50:47

forward slashes that indicates uh the start of a  comment and anything after that for that entire  

play50:55

line will not be treated as code so this is just  information right this is not code that actually  

play51:01

gets run so for example as I'm writing this  code and I want to remind myself what these  

play51:07

things are I can write two forward slashes and I  can write vertical stack layout and that is just  

play51:17

treated as documentation it's not code that will  be run I can write it here image for the plant  

play51:24

I can write down here label for whatever now this  is not the best use of a comment because this is  

play51:34

just describing what this element is anyone who  is fluent in Reading Swift Code can immediately  

play51:41

see this and that makes your comment irrelevant  like they're just going to understand what this is  

play51:45

oh I know that's an image I know that's a label  I know that's a vertical stack the best use of  

play51:50

comments is actually to describe your logic in  your head so if you have multiple people working  

play51:58

on the same project or you're going to pass off  this project to someone else it's very helpful  

play52:04

to describe why you're doing the things you are so  it's literally like uh you know a note that says  

play52:11

you know I'm doing this because of this  or whatever and like watch out for this so  

play52:19

when someone reads your code they can read these  comments and get the context for why you're doing  

play52:24

what you're doing the other cool thing you can do  with comments is you can comment out lines of code  

play52:29

for example you want to test something you don't  want to print hello just put two forward slashes  

play52:35

in front of it and when you put two forward  slashes like that the it's not going to execute  

play52:40

that line of code and you can very easily just  uncomment it if you want to comment out multiple  

play52:44

lines of code you can also use forward slash star  and star forward slash and anything in between  

play52:51

those two markers will be treated as a comment as  you can see here can see here on the preview it's  

play52:58

going to disappear okay so that's commenting  and documentation the other thing I want to  

play53:03

show you is navigating around in the editor area  because that's where you're going to be spending  

play53:07

a lot of time so this breadcrumb area at least  that's what I call it I don't know if that's the  

play53:12

official name but you can see it's sort of like  a breadcrumb where there's your root node folder  

play53:17

there's your file and this is within the current  file so if this file gets really long and there's  

play53:22

a lot of code you can tap on something to jump  right to that section now that you know how to  

play53:27

use comments you can actually also put different  sections yourself using comments for example  

play53:35

this is this is the format you would use you type  mark followed by colon and a line and you can say  

play53:41

this is uh for previews you can see this is bolded  because this is a special syntax right here and  

play53:49

you can also see a line going across which gives  you some visual separation and when you tap on  

play53:55

this now you can see that that note is right there  and there's a line here so that helps you sort of  

play54:01

uh section your file and group group your long  code file into more legible chunks now the other  

play54:09

thing is that when you start adding views you're  going to have more files and sometimes you'll be  

play54:13

working in this area then you're going to jump  to another file and work in this area and then  

play54:18

you just want to go back so instead of tapping  on this file and going back here you can very  

play54:24

easily use the back and forward arrows they work  just like a web browser back and forward so this  

play54:31

is very handy there are even shortcut keys  to do this as well so you can find them in  

play54:37

here and navigate go forward and backward this  is your your keys right here another thing is  

play54:43

that sometimes and you saw me use this earlier  sometimes when let's say your code gets really  

play54:48

long and you want to collapse this element because  all of this code right here is inside this v-stack  

play54:55

so you can collapse it and there's also shortcut  keys for this this one I usually use right here  

play55:03

code folding fold and unfold this I usually just  use shortcut keys so for me it's command option  

play55:12

and then left or right and that will collapse it  so you can do that now I'm going to talk about  

play55:18

searching through your project first of all if  you press command F you're going to bring up  

play55:23

this little search menu here and you're going to  be able to look for something inside this current  

play55:27

file right there but if you want to search  throughout your entire project you can also  

play55:32

do that press command shift and F and that you're  going to be looking through your entire project

play55:41

okay it's going to tell you all the lines here and  this is useful in some cases as well tapping on  

play55:46

any of these lines will bring you to exactly that  file in that section all right now I want to talk  

play55:52

about bringing up documentation because that is  oftentimes very helpful when you're starting to  

play55:59

learn so you can either place your cursor on  the component and then you can come here into  

play56:05

the quick help right here and you can look at  the quick help documentation here if that's not  

play56:09

enough you can also open developer documentation  and open that up right here however there's an  

play56:15

easier way if you hold down option and you see  that when I hover over image my cursor turns into  

play56:22

a question mark and I tap on that it's going to  bring that up right there so hold down option or  

play56:29

alt it may be on your keyboard and it turns your  cursor into question mark so that's really helpful  

play56:35

so I hope that was helpful if you ever  need a reminder simply use the timestamps  

play56:39

and chapters below the video and if you want  to keep growing your app development skills  

play56:43

I recommend that you try our beginner  app challenge next it's going to help  

play56:46

grow your app skills and give you more  practice inside xcode I'll see you there

Rate This

5.0 / 5 (0 votes)

Related Tags
Xcode TutorialiOS DevelopmentApp BuildingSwift UICoding GuidePublish AppsApple SoftwareMobile AppsDeveloper ToolsProgramming Tips