Introduction to Objective-C Spring 2013. Goals An introduction to Objective-C As implemented by the Apple LLVM Compiler 4.0 (a.k.a. Clang) Only the basics…

Slides:



Advertisements
Similar presentations
Lecture 2 - Introduction Objective C is used primarily for application development on Apple's Mac OS X and iPhone. On the Apple it is used together with.
Advertisements

Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
ARDUINO CLUB Session 1: C & An Introduction to Linux.
The Preprocessor Underlying C Language Features Copyright © 2012 by Yong-Gu Lee
Compiler Design PROJECT PRESENTATION : COMPILER FOR OBJECTIVE C Harshal Waghmare Jeet Kumar Nandan Kumar Vishal Agrawal.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to Objective-C and Xcode (Part 1) FA 175 Intro to Mobile App Development.
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
Datalogi A 1: 8/9. Book: Cay Horstmann: Big Java or Java Consepts.
Android Application Development Stephen Diniz Computer/Electrical Engineer Lecture 01 Introduction.
1 ICS103 Programming in C Lecture 2: Introduction to C (1)
Friday, August 29, 2014 CSCI 351 – Mobile Applications Development.
Handybook: Swift Jayant Sani. Handybook Opinions “It’s like Ruby on Rails, for iOS!” – Nikita “A function should only do one thing and return.
Objective-C Quinton Palet. Introduction  Objective-C was developed to bring large scale software development the power of the object-oriented approach.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Computer Science 210 Computer Organization Introduction to C.
Ping Zhang 10/08/2010.  You can get data from the user (input) and display information to the user (output).  However, you must include the library.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
Refactoring Moving a console app to a UI app. Refactoring Goal: change a console app to a UI app Principles: The main.m goes away The local variables.
Xin Liu Sep 16, Introduction Xin (Shane) Liu PhD Candidate in Computer Science Research Area: Computer Graphics Tutorial Page: pages.cpsc.ucalgary.ca/~liuxin/CPSC453.
UNIVERSITI TENAGA NASIONAL “Generates Professionals” CHAPTER 4 : Part 2 INTRODUCTION TO SOFTWARE DEVELOPMENT: PROGRAMMING & LANGUAGES.
Object Oriented Programming
Introduction to Objective-C and Xcode (Part 3) FA 175 Intro to Mobile App Development.
Objective C Basics. It’s C with Some Extras!  Cross Platform language  Mac  Linux/UNIX  Windows  Layer above C (Superset)  Adds Object-Oriented.
OS X Development Tom Schroeder. Table of Contents Who cares? HistoryObjective-CCocoaEnvironmentDesign.
Objective-C First Part adapted from a presentation by Kevin Layer.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Objective-C OOP Spring OOP Conceptually the same as C++, Java, and all other object oriented languages The syntax, however… …is, well, different.
1 Introduction to Objective-C Programming (Level: Beginner) Lecture 1.
ECE Application Programming Instructors: Dr. Michael Geiger & Nasibeh Nasiri Fall 2015 Lecture 2: Basic C program structure Data in C: Data types,
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
APS105 Strings. C String storage We have used strings in printf format strings –Ex: printf(“Hello world\n”); “Hello world\n” is a string (of characters)
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Monday, August 31, 2015 CSCI 351 – Mobile Applications Development.
Lecture 3: Getting Started & Input / Output (I/O) “TRON” Copyright 1982 (Walt Disney Productions)
Introduction to Programming
Nav Controllers UINavigationController. Overview Nav Controller basics Like a tabview controller, a navViewController manages views A navigationViewController.
Objective-C Drew Cheng CS420. Overview True superset of ANSI C Object-Oriented methods from SmallTalk There is no formal written standard for the language.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
Monday, August 31, 2012 CSCI 333 – Systems Programming.
The iOS Platform and SDK. iOS iPhoneiPad Mini iPad.
1 Reverse a String iPhone/iPad, iOS Development Tutorial.
CS429 Computer Architecture Topics Simple C program Basic structure, functions, separate files Compilation Phases, options Assembler GNU style, byte ordering,
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
13. Strings. String Literals String literals are enclosed in double quotes: "Put a disk in drive A, then press any key to continue\n“ A string literal.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
2014 CS Mobile Computing (iOS) Dr. William C. Bulko CS 378 – Mobile Computing (iOS) Introduction.
Lecture 3: Getting Started & Input / Output (I/O)
Eclipse.
Development Environment
CSCI 351 – Mobile Applications Development
Computer Science 210 Computer Organization
A bit of C programming Lecture 3 Uli Raich.
ICS103 Programming in C Lecture 3: Introduction to C (2)
CSCI 351 – Mobile Applications Development
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Computer Science 210 Computer Organization
The Designer.
EEC-492/693/793 iPhone Application Development
EECE.2160 ECE Application Programming
CSC 581: Mobile App Development
Getting Started With Coding
Presentation transcript:

Introduction to Objective-C Spring 2013

Goals An introduction to Objective-C As implemented by the Apple LLVM Compiler 4.0 (a.k.a. Clang) Only the basics… See the class web page for references: Reference->Objective-C Most of the references are WRONG about memory management Now ARC takes care of memory management for you!

History Brad Cox created Objective-C in the early 1980s Added object-oriented programming concepts to the C programming language NeXT Computer licensed the language in 1988 Used it to develop the NeXTSTEP operating system, programming libraries and applications for NeXT In 1993, NeXT worked with Sun to create OpenStep, an open specification of NeXTSTEP on Sun hardware

History In 1997, Apple purchased NeXT and transformed NeXTSTEP into MacOS X which was first released in the summer of 2000 Objective-C has been one of the primary ways to develop applications for OS X ever since In 2008, it became the primary way to develop applications for iOS

Objective-C Objective-C adds classes to C through a small set of extensions It is used with two object-oriented frameworks: The Foundation framework contains classes for basic concepts such as strings, arrays and other data structures and provides classes to interact with the underlying operating system The AppKit contains classes for developing applications and for creating windows, buttons and other widgets Together the Foundation and AppKit frameworks are called Cocoa

Objective-C On iOS, AppKit is replaced by UIKit Foundation and UIKit together are called Cocoa touch In this lecture, we focus on the Objective-C language, we’ll see a few examples of the Foundation framework we’ll see examples of UIKit later

Objective-C Objective C is C All of C code will work. Memory management not necessary with ARC Classes are based on Smalltalk syntax It’s a bit, well, weird.

XCode Apple’s development tool Only tool you can use to develop native apps for iOS Makes use of Apple’s Clang compiler Based on LLVM Used to use the gnu compilers, but Apple wanted to extend the compiler without open-sourcing the code LLVM is a highly-optimized compiler Xcode also contains Interface Builder, a tool for creating iOS GUI interfaces via drag ‘n drop.

Example Create a new project as you did with the C++ program. In the first dialog box choose “OS X” and “Application” Choose “Command Line Tool” hit “next” Enter a name. Make sure the “Type” is Foundation Make sure to check the checkbox next to “Create local git repository for this project” when you choose where to locate the project. A project will be created and you’ll get the file “main.m” The “.m” stands for “messages” Insert the code on the next slide

Example #import int main(int argc, const char *argv[]) { NSLog Objective-C!”); } return(0); } // main Instead of include import will ensure that the file is only included once. NSLog is the printf of the Foundation frameworks. Also prints date & time and a newline signifies a NSString. NS = NextStep This is a string class like that found in Java Most Foundation framework classes expect a NSString not a C style string!

Interlude notice that an “M” appears to the right of main.m after you edit it. The M is an aspect of XCode’s git integration. It’s telling you that the file was modified and that (eventually) you can check these changes into the git repository XCode automatically created the git repository for you.

Example 2 #import int main(int argc, const char * argv[]) { char getName[32]; printf("Enter a name: "); scanf("%s", getName); printf(“Hello %s\n”, getName); } return 0; }

Example 2.1 #import int main(int argc, const char * argv[]) { char getName[32]; printf("Enter a name: "); scanf("%s", getName); // Note the use of a “C” string %s !", theName); } return 0; }

Example 2.2 #import int main(int argc, const char * argv[]) { NSString *theName; char getName[32]; printf("Enter a name: "); scanf("%s", getName); theName = [NSString stringWithCString:getName encoding:NSASCIIStringEncoding]; theName); } return 0; } It’s complicated to convert a C string to a NSString! Note the format for NSString NSString is defined in the Foundation framework

Example 3 int main(int argc, const char * argv[]) { BOOL areTheyDifferent; areTheyDifferent = areIntsDifferent (5, 5); NSLog %d and %d different? 5, [NSString areTheyDifferent = areIntsDifferent (23, 42); NSLog %d and %d different? 42, [NSString } return 0; } BOOL is a Foundation type Different from a C language “bool” In Foundation library have constants for BOOL type: YES = 1 NO = 0

Example 3 // returns NO if the two integers have the same // value, YES otherwise BOOL areIntsDifferent (int thing1, int thing2) { if (thing1 == thing2) { return (NO); } else { return (YES); } } // areIntsDifferent

Example 3 // given a YES value, return the human-readable // string "YES". Otherwise return "NO" NSString *boolString (BOOL yesNo) { if (yesNo == NO) { return } else { return } } // boolString