IPhone Development Crash Course By Dylan Harris 9-19-11.

Slides:



Advertisements
Similar presentations
Objective-C Lecture 2 Memory management Memory management in OC is semi- automatic: The programmer must allocate memory for objects either a) explicitly.
Advertisements

Lecture 3 - Writing Initializers A correct initializer must comply with the following: The initializer name should begin with init The initializer returns.
Based on Java Software Development, 5th Ed. By Lewis &Loftus
Python Objects and Classes
Introduction to Objective-C and Xcode (Part 1) FA 175 Intro to Mobile App Development.
CS 3800 Su 11 Beg. IOS Dev L4 Obj C part 1 CS 3800 Introduction to IOS programming Summer 2011 G. Zimmerman.
Informática II Prof. Dr. Gustavo Patiño MJ
Anatomy of an iPhone Application Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
IPhone Development JaxCodeCamp Who am I David Fekke.NET Developer, ColdFusion Work at LPS Presenter JaxDug, JaxJug, JSUG & JaxFusion Mac User 1986.
IPhone 101. Outline Objective-C Random bits of the API Using the simulator Debugging with Xcode.
IStarted- And You Can Too! A Beginner’s Guide to iOS Programming.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
3-Jul-15 Chapter 2 iPhone App Store and App Business Issues.
1 Objective-C Foundation Lecture Flow of Lecture 2  Objective-C Basics  Introduction to Objective-C  Intrinsic Variables and Image-Specific.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
Objective-C Quinton Palet. Introduction  Objective-C was developed to bring large scale software development the power of the object-oriented approach.
Memory Management and Automatic Reference Counting/ Copying Objects Archiving Copyright © 2012 by Yong-Gu Lee
IOS WorkShoP Xcode 4 iOS 5 : “A Primer”. Objective-C iOS applications are written in Objective-C language using the Cocoa Touch library Objective-C is.
1 Python Control of Flow and Defining Classes LING 5200 Computational Corpus Linguistics Martha Palmer.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Introduction to Objective-C and Xcode (Part 2) FA 175 Intro to Mobile App Development.
Object Oriented Programming
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Objective C Basics. It’s C with Some Extras!  Cross Platform language  Mac  Linux/UNIX  Windows  Layer above C (Superset)  Adds Object-Oriented.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
OS X Development Tom Schroeder. Table of Contents Who cares? HistoryObjective-CCocoaEnvironmentDesign.
Objective-C First Part adapted from a presentation by Kevin Layer.
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.
Objective-C1 CS151 Presentation: Objective C Kai Tai Pang William Sze.
Objective C. Основан на C Объектно-ориентированный Использует сообщения Динамический Протоколы Интроспекция.
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Objective-C Memory management Memory management is semi-automatic: The programmer must allocate memory for objects either a) explicitly (alloc) or b) indirectly.
Course Summary Xcode & iPhone Simulator
More C++ Features True object initialisation
Polymorphism, Dynamic Typing, and Dynamic Binding Copyright © 2012 by Yong-Gu Lee
Copyright Curt Hill Variables What are they? Why do we need them?
CS451 - Lecture 2 1 CS451 Lecture 2: Introduction to Object Orientation Yugi Lee STB #555 (816) * Acknowledgement:
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
OOP with Objective-C Categories, Protocols and Declared Properties.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming - Week.
The iOS Platform and SDK. iOS iPhoneiPad Mini iPad.
Object-Based Programming in VB.NET. Must Understand Following: Encapsulation Information hiding Abstract Data Type Class, Instance, Reference Variable.
Lec 5 Obj-C part 2 CS 3800 Introduction to IOS programming Lecture 5 Summer 2011.
OBJECTIVE C Kurt Ladendorf. General Knowledge  Super set of C  Smalltalk  Mainly used for iOS and other Apple development.
IOS Programming Medialogy, Semester 7, 2010 Aalborg University, Aalborg David Meredith
(c) University of Washington06-1 CSC 143 Java Inheritance Tidbits.
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
Learning & Development Mobile apps for iPhone & iPad.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Introduction to Objective-C and Xcode (Part 4) FA 175 Intro to Mobile App Development.
MORE on classes in …... OOP terminology in Objective-C Class: defines the grouping of data and code type of entity Object or Instance: a specific instantiation.
Objective-C: Intro Michelle Alexander COMS E6998 2/4/2013.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Introduction of Object Oriented Programming.
FASTFAST All rights reserved © MEP Make programming fun again.
Course Summary Xcode & iPhone Simulator
iStarted- And You Can Too!
Java Primer 1: Types, Classes and Operators
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
EEC-492/693/793 iPhone Application Development
CS212: Object Oriented Analysis and Design
Pointers, Dynamic Data, and Reference Types
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
CISC/CMPE320 - Prof. McLeod
Pointers, Dynamic Data, and Reference Types
SPL – PS3 C++ Classes.
Presentation transcript:

iPhone Development Crash Course By Dylan Harris

For the tutorials Xcode 3 or 4 working and installed? Right now only a few ways to get Xcode 4 – Upgrade to Lion, get of app store for free – Sign up for $100 developer account Maybe it will become free when iOS 5 releases?

Topics today iPhone Development Overview Objective-C Language Basics Custom classes Memory management basics Tutorials throughout

Getting help API & Conceptual Docs – Found in Xcode under help menu – Also found on developer.apple.com Class header files The Internet – Stack Overflow, blogs, iTunes U(Stanford classes)

Model-View-Controller iPhone dev uses the MVC design pattern Model: Manages the app state and data View: Presents the Model to the user in an appropriate interface Controller: Middleman between the Model and the View

Cocoa Frameworks Foundation – Check out object docs NSString – Objective-C string is a string” NSArray, NSDictionary, NSSet Their “mutable” counterparts UIKit – User interface elements

Objective-C Strict superset of C – Mix C with ObjC Single inheritance – Classes inherit from one and only one superclass Protocols define behavior that cross classes Dynamic runtime – All variables declared on heap Loosely typed, if you want

Syntax Additions New types – id: anonymous object, allows for loose typing – Class: a class is also an object – Selector: like a function pointer Syntax for message expressions – [receiver message:argument];

Message Syntax [receiver message] [receiver message:argument] [receiver message:arg1 andArg:arg2]

An example Person *person; //assume exists [person walk]; – (void)walk; int theAge = [person age]; – (int)age; [person setAge:25 andHeight:60]; – (void)setAge:(int)age andHeight:(int)height; NSString* spouseName = [[person spouse] name]; – (Person*)spouse – (NSString*)name

Terminology Message expression – [receiver method: argument] Message – [receiver method: argument] Selector – [receiver method: argument] Method – The code selected by a message

Classes and Instances Both classes and instances are objects Classes are messaged to create instances Instances respond to instance methods – (id)init; – (void)walk; Classes respond to class methods +(id)alloc; +(Person*)sharedPerson; You can ask an object about it’s class(introspection)

Dot Syntax Convenient shorthand for invoking accessor methods float height = [person height]; float height = person.height; [person setHeight:newHeight]; person.height = newHeight; Follows the dots... [[person child] setHeight:newHeight]; // exactly the same as person.child.height = newHeight;

Tutorial Hello World Follow along if Xcode and iPhone SDK installed Use Simulator

Null Object Pointer Test for nil explicitly – if (person == nil) return; Or implicitly – if (!person) return; Can use in assignments and as arguments if expected – person = nil; – [button setTarget: nil]; Sending a message to nil? Perfectly fine – person = nil; – [person walk];

BOOL typedef When ObjC was developed, C had no boolean type (C99 introduced one) ObjC uses a typedef to define BOOL as a type – BOOL flag = NO; Macros included for initialization and comparison: YES and NO (TRUE and FALSE are also typedef) – if (flag == YES) – if (flag) – if (!flag) – if (flag != YES) – flag = YES; – flag = 1;

Custom classes Inherit from NSObject.h is header.m is implementation

Header file interface Person : NSObject { // instance variables NSString *name; int age; } // method declarations - (NSString *)name; - (void)setName:(NSString *)value; - (int)age; - (void)setAge:(int)age; -

Getter/setter methods #import Person -(int)age { return age; } -(void)setAge:(int)value { age = value; } //... and other

Action methods #import Person -(BOOL)canLegallyVote { return ([self age] >= 18); Note the “self” object, same as this pointer in C++ Can also call “super” to access methods in the superclass – [super dosomething];

Object creation Two step process – Allocate memory to store the object – Initialize the object state [[Person alloc] init] returns a new Person Can have other init methods – [[Person alloc] initWithAge:25];

Reference Counting Every NSObject has a retain count +alloc and -copy create objects with retain count of 1 -retain increments retain count -release decrements retain count Retain count reaches 0, -dealloc automatically called and object is destroyed Person *person = [[Person alloc] init]; [person doSomething]; [person release];

Reference counting in action Person *person = [[Person alloc] init]; Retain count begins at 1 with +alloc [person retain]; Retain count increases to 2 with -retain [person release]; Retain count decreases to 1 with -release [person release]; Retain count decreases to 0, -dealloc automatically called

Autorelease Example: returning a newly created object -(NSString *)fullName { NSString *result; result = [[NSString alloc] firstName, lastName]; [result autorelease] return result; }

Method Names & Autorelease Methods whose names includes alloc, copy, or new return a retained object that the caller needs to release NSMutableString *string = [[NSMutableString alloc] init]; // We are responsible for calling -release or -autorelease [string autorelease]; All other methods return autoreleased objects NSMutableString *string = [NSMutableString string]; // The method name doesn’t indicate that we need to release it, so don’t This is a convention- follow it in methods you define!

Properties Shortcut for implementing getter/setter methods

Defining Properties Person : NSObject { // instance variables NSString *name; int age; } // method declarations - (NSString *)name; - (void)setName:(NSString *)value; - (int)age; -

Defining Properties Person : NSObject { // instance variables NSString *name; int age; } // method (copy) NSString* int

Synthesizing Person - (int)age { return age; } - (void)setAge:(int)value { age = value; }

Synthesizing age; - (void)setAge:(int)value { age = value; // now do something with the new age value... } Can mix and match synthesized and implemented properties – Synthesize age, but implement setAge – Getter method still synthesized

Property Attributes Read-only versus int age; // read-write by (readonly) BOOL canLegallyVote; Memory management policies (only for object (assign) NSString *name; // pointer (retain) NSString *name; // retain (copy) NSString *name; // copy called

Tutorial Follow along if Xcode and iPhone SDK installed Use Simulator

Comments/Questions?