Basic Objective-C Syntax

Alec Kriebel
A free video tutorial from Alec Kriebel
Current Freelance iOS Dev, iOS Developer of 5 years, Former Lead iOS Developer @ Instamour
4.2 instructor rating • 1 course • 1,173 students

Lecture description

This lesson goes over the basic structure and format of the Objective-C programming language, one of two programming languages used to develop iOS apps and also Mac applications. Objective-C is an object oriented version of C and was adopted by Apple and utilized by the Cocoa API, or Cocoa Touch API in iDevices.

Learn more from the full course

How To Develop iOS Apps Course: No Experience to App Store

The How To Develop iOS Apps course is a video course that teaches anyone, no experience needed, to develop iOS apps.

10:43:26 of on-demand video • Updated September 2015

  • The ability to create any iOS app
  • The knowledge needed to launch apps globally on the App Store
  • Be able to understand the Objective-C programming language
  • Acquire the knowledge needed to learn any programming language you need
English [Auto] Chapter 3 lesson one basic syntax building iPhone apps requires basic knowledge of the programming language Objective-C in this tutorial we're going to show you the basic syntax of Objective-C learning a programming language is like learning a second language. Except in this case you're learning a language that the computer can understand immediately. I'm going to open X code and navigate to get a new project for this. I'm going to use single view application on so I filled in the basic details from my project. I'm going to go to The View control or dot m file that X code has generated for us. The first thing I want you to notice in this view for file is the view did load statement on line 17. Notice directly after load. There is a curly bracket and then a few lines down. There's an end curly bracket in Objective C all brackets or parentheses must be closed by another bracket. So if we have one that opens we have one that must close at the end curly bracket a view did load statement effectively ends the method there. Anything outside of it is not considered in the view to load method in between the curly brackets. You did load. I'm going to type and s log. Open print see at quotes. This is a log entry end quote and print the C semi-colon. Let's take a look at this line of code that I just wrote using and Aslaug will print something in the bottom log. When this app is run now in this case what it will print is this is a log entry. Now notice the parentheses. They both open and close and whatever is in between this front sees is what analog will print. Now almost always this is going to be a string a string is depicted by the quotes. Anything between that quote and whatever ends the quote is considered a string. In this case our string is. This is a log entry at the end of this line of code. Is Michael let's see what happens if we don't add a semi colon to another line of code. Notice that we now have a red line and this line of code I just wrote I wonder why it's because we didn't add a semicolon. Now a semi-colon is used to denote the end of a line an object of C almost all lines of code in Objective C require a semi-colon a semi-colon is like a period to the end of a sentence in the English language. If you don't have a semicolon it doesn't know whether the line of code stops. So essentially semi-colons are used to end lines and Aslaug is what we'll be using to demonstrate a lot of lessons in this series. Where do you use it to print certain functions to show how things work and Aslaug is useful because our end user the user that uses the app once you've created and release it we'll never see M-S log. It's purely for developer support typing slash slash. We're essentially void that line. Anything after the slash slash that line of code will become green and will be overlooked by the compiler. This is called the comet. Now a comment is useful for writing some standard English or any language text inside of a piece of code because it will be overlooked. You can write anything you want in there and you won't get errors trying to write standard text inside of a piece of code without comment will result in an error simply Objective-C. The language can't understand what you're trying to write. It doesn't understand English using slash slash will simply void that line of code and only that line of code. If we want to avoid multiple lines of code what we can do is type slash asterisk. This will avoid as many lines of code as you want. Until you type asterisked slash simply put slash asterisked will open a comment and asterisks slash will end the comment. It's a multi-line comment. Of course there's more syntax to cover but this is the basic syntax. We'll need to know to learn most of the other syntax that will be coming in future lessons.