- [Instructor] In this movie,
I'll show you how to create a workspace in Xcode
for following along with the course exercises on a Mac.
Xcode is free on the Mac App Store.
It requires a modern Mac running a recent version of OS10
or macOS, whatever they call it this week.
I have already installed Xcode on this Mac,
and I have placed the exercise files on the desktop,
which you can see over here.
And so I'm going to go ahead and close the App Store
and I'm going to start up Xcode here.
And you notice the Xcode starts with a blank screen.
I'm using Xcode 11.6 on macOS Catalina.
And if you're running a later version,
that should be just fine,
That shouldn't be a problem at all.
So we're going to create a new workspace.
We're going to come in here.
We're going to say file new
and we're going to select workspace.
So what a workspace is, is a space where you can keep
a collection of different things
that you're going to work with together.
And Xcode is an absolutely brilliant IDE.
You're going to love working in it, if you haven't already,
I think it's one of the best IDEs available
anywhere right now.
So anyway, a workspace works like this.
I'm going to put it in my documents folder
and you can put it wherever you like,
as long as you know where to find it.
And I'm going to just name it, CppWorkspace, like that.
And you need to leave the XC workspace Xcode workspace
file extension there.
And I'm going to start here, my documents folder.
And so I'm going to say save,
and that's it.
We now have a workspace which is ready
and as you can see, it's empty.
So I'm going to add a folder reference.
And so I'm going to go ahead and I'm going to add files.
So I'm going to come here and I'm going to say
add files to CPP workspace.
But what I'm going to do is I'm actually going to
add folder references rather than copying the files.
So I'm going to unselect copy and say,
create folder references.
And then here on my desktop,
I'm going to select the exercise files.
And when I say add here,
you notice that my exercise files now show up here
in my workspace.
And yet, if I look at them,
you see that the file location is still on my desktop.
So this is not even a copy.
This is just a reference to those files,
but allows me to use them, which is really, really great.
So now I'm going to create a project for us to compile
and actually work with the code.
And so I come up here to file and new and say new project.
And I've already selected here, macOS, but you see
that there's a lot of different types of projects.
All IDEs are like this.
They have all kinds of things you can do.
All we're going to do here as a command line tool
under macOS command line tool.
And I'm going to say next,
and I'm going to name my, now it's calling it a product,
but I'm going to name that, I'm going to call it working.
You noticed this feels the same
because I've used Xcode before.
And these are settings that I had before.
It doesn't really matter much what you put there.
You can add an account or not add an account,
but you do want to select C plus plus for your language.
You have these other choices
and you want to select C plus plus for language
and then select next.
Now it's going to say, where do you want to save it?
And I'm going to go ahead and save it in my documents folder.
And that's fine.
You do not want to get repository.
And unless you really want that, but you don't need it.
What you do need to do is,
you need to add it to your workspace.
And so you can put it anywhere.
You want to put it in the top level, under CPP workspace,
and you want to add it to the workspace.
And now when I select create,
you notice that my working project here
is now in my workspace, along with my exercise files.
So the first thing we're going to do is
we're going to look at this main
and we're going to say, okay, well, there's what that is.
And we're going to go ahead and delete it.
And if you select the file and hold down,
command and delete,
you'll get this old dialogue
and you can move it to the trash,
which also happens if you press command and delete again,
but that's okay.
And that's where you want to put it.
And instead, we're going to come into
our chapter two exercise files,
and we're going to grab, hello.cpp.
And I'm a hold down the option key.
While I drag this up here
and you notice I get a green plus sign,
I'm going to put it in the working folder there.
And when I let go of it, I get the style of box.
You want to make sure copy files is selected now
and add to targets working as selected and select finish.
And now when I select this,
you'll notice my location is now in my working project.
While the original one that is in my exercise files
is still in my desktop exercise files.
So we've made a copy of this into our project,
which is exactly what we want to do.
So now we don't need this right panel anymore.
And I'm going to go ahead and press command R,
which will compile and run.
And the first time you run something,
in a newly installed project, always takes a minute
in the future it won't take long at all.
And you notice we get our result down here, hello, world!
And so this is our console application,
and we actually have a console down here.
We don't need to run it
in a separate terminal application or anything.
It runs it right here in the IDE,
which is really great, and that's what we're looking for.
You notice there's also another pane off
here to the left for debug.
I'm just going to close that by pressing
all the way down here in the lower, right?
You see you have the two little icons,
the left one will open and close that left window.
And that way we've got all of this space
for our command output.
Now you'll notice that I have really big letters
here on the screen.
I've set up a special profile here on this Mac.
If I come into Xcode preferences or press command comma,
you'll notice under fonts and colors.
I have my own theme here for recording.
The big text makes it easy to see on this little screen
for the recording,
but you can select any of these themes or create your own,
however you want to do that.
There's a lot of options here
for a lot of different purposes,
but if you look under text editing,
you'll also see, I mean, denting by four characters.
And I have these options here,
which you can play with and customize the screen,
however we like it.
So now that I have compiled this, you notice under products,
we have this working executable.
And if I right click on this and say, show in finder,
you'll notice that, you know,
there's this whole big path to this file here,
which is under products and build,
and it's long crazy thing, but that's where it is.
And what's interesting here is when I run clean, which is,
I think under product here.
Yeah, Clean Build Folder, Shift, command, K.
That it'll actually delete.
And we go back out here to the finder,
you see all that's deleted.
It has deleted that.
And it turns it red here because we've deleted it.
And now I can command R and build again.
And you see that it shows up again there.
And so when we're done with a file
and we're going to delete our hell.cpp here now,
and again, command, delete and command, delete again,
which moves it to the trash.
And you see it still exists down here in our exercise files,
but we've deleted it from our working product
and I can run Shift command K,
and it will clean our product and reset everything
so that we can compile a different file.
So you're going to want to do that after every exercise,
you're want to delete your source file
and run clean with Shift command K.
So the whole purpose of hello, world!
Is to test your developer environment,
test your development cycle,
to make sure that you can edit a file
that you can compile it.
You can run it and delete, and in all of that.
So we've now learned how to do all of that.
And now we're going to do the same thing again,
but this time with this cpp11.cpp.
So option drag it up here and copy items and finish
and come up here and select that.
And we can see that this is the one that's in our project.
And this one down here is in our exercise files.
We've got that path up here as well.
And our working is still red because we haven't compiled it,
and we still have the output from our last one.
So if I now press command R it will build this one
and it will run it.
And all this code does, is it tests to make sure
that we're running the latest version of a compile,
running a compiler that will run all the modern features
in a modern C plus plus compiler.
So now I can delete that from our working project,
command, delete, command, delete again, this turns red,
this is still here and I can run clean Shift command K.
And now you're ready to follow the exercises in this course,
you've installed your workspace.
You've installed your project,
you know how to navigate all of that.
And so it's an excellent IDE and it's compiler Clang
is a superb compiler,
and this combination provides a great environment
for this course.