Kittens on Keyboards
This post will tell you about the basic types of variables.
First of all, there are no semicolons in Swift (*does the happy dance*). That means no more endless searching for that one semicolon that you missed that messed everything up. All variables are declared using var. Sometimes, xCode is smart enough to recognize the type of variable, so that is the only thing you need. For example: var str = ''Probably Rainbow Unicorns" // str will automatically be set as a String var count = 1 // count will automatically be set as an Int var toggle = true // toggle will be set as a bool Some of you may already see the problem. What if count is actually a double? You could declare it as var count = 1.00 but there is a better way to do this. The colon! You can declare the type of variable using a colon after the variable name. var counter: Double = 1 var str1: String = "Definitely Rainbow Unicorns" At times, however, you know you need a variable, but you don't want it to have a value yet. For example, if you want a user to sign up for an account on your app, you know that user is going to create a username and password.
0 Comments
Lets look at the first option you are given when you open xCode: Get Started With A Playground. If you click on the option, you should get something like this: Go ahead and name the playground anything you want. You want the platform to be iOS because OS X is a much older platform, and most apple devices no longer run it. However, it doesn't really matter because this is a playground. On the bottom right corner, there are two buttons: Previous, and Next. Previous is a wierd button. I recommend you do not press it. It will take you to this screen: We can talk more about the types of files you are seeing here, but for now I can tell you that the 4 types of files in the bottom row are Objective C files. We will be writing in Swift, not Objective C, so you will not need them 99.9% of the time. The types of files in the top row, except for playground, you will need when you begin to create an actual app. If you do click the previous button, click on before you click next, or you will get a strange disembodied part of an app that does nothing, rather than an actual playground. Now click the Next button. You should have a screen like this: However, there may be no files in the square on the right. Once again, that is because I have previous xCode projects, while you probably do not. Decide where you want to save your file now. I am saving my files in Desktop, but you could save them in Documents or anywhere else. I would recommend a new folder. Then click Create. You should be taken to a screen like this: I'm assuming that you have some basic programming experience. I just want to explain the xCode layout. When you open xCode up for the first time you should get something like this: You can see the column on the right in the picture has several files (those colored rectangles). However, your column may be empty. This is because that column shows previous projects, and you do not have any previous projects. The square on the left has 3 options: ~ The top option (Get Started With a Playground) does not let you create an app. If you have some basic computer knowledge, it is basically useless. Otherwise, it is a good place to experiment with how to create variables and simple functions. ~ This middle option (Create a New xCode Project) is the one you will probably use the most if you are trying to create iPhone apps. This gives you the required files and the layout to create an app. ~ The bottom option is not one you will use if you are new to xCode. Personally, I have only used it once. It lets you import projects you may have saved on websites such as Github and work on projects you have tagged as favorites. |
Sara SubbannaStudent whose life is currently a dark swirly void of confused bird noises. |