CS 3800 Su 11 Beg. IOS Dev L4 Obj C part 1 CS 3800 Introduction to IOS programming Summer 2011 G. Zimmerman.

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.
Black Jack in Objective-C
Basic Object-Oriented concepts. Concept: An object has behaviors In old style programming, you had: –data, which was completely passive –functions, which.
Lecture 5: Interfaces.
Based on Java Software Development, 5th Ed. By Lewis &Loftus
suppose you had Bumblebee, Jet, and Bird classes. All three, although unrelated, implement the flying behavior, and so you could say they are each a Flyer.
Introduction to Programming Lecture 39. Copy Constructor.
Programmer-defined classes Part 2. Topics Returning objects from methods The this keyword Overloading methods Class methods Packaging classes Javadoc.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Web Application Development Slides Credit Umair Javed LUMS.
Operator Overloading Fundamentals
Programming in Objective-C Classes, Objects, and Methods Data Types and Expressions Copyright © 2012 by Yong-Gu Lee
Based on examples in "Programming in Objective-C," Copyright © 2004 by Sams Publishing O BJECTIVE -C Q UICK & D IRTY.
Class and Objects.
1 CS2200 Software Development Lecture 27: More Testing A. O’Riordan, 2008 K. Brown,
CS 106 Introduction to Computer Science I 11 / 09 / 2007 Instructor: Michael Eckmann.
Anatomy of an iPhone Application Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
IPhone Development Crash Course By Dylan Harris
IPhone 101. Outline Objective-C Random bits of the API Using the simulator Debugging with Xcode.
Introduction to Data Structures, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure Object Oriented Programming Concepts.
Intro to Objective-C Syntax: What’s most confusing about Objective-C? Most class names start with NS: NSString, NSObject Parameter lists are not comma.
CMSC 2021 Stream I/O Operators and Friend Functions.
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
More on Classes Inheritance Copyright © 2012 by Yong-Gu Lee
Object Oriented Programming
COSC 1P03 Data Structures and Abstraction 4.1 Abstract Data Types The advantage of a bad memory is that one enjoys several times the same good things for.
Basic Object- Oriented Concepts Presented By: George Pefanis 21-Sep-15.
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.
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.
Objective-C1 CS151 Presentation: Objective C Kai Tai Pang William Sze.
Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 02 – Classes, Objects, Instances Richard Salomon and Umesh Patel Centre.
1 Overloading Overloading allows a function or operator to have a different meaning depending on the type of objects it is used on. Examples: operator+
Objective C. Основан на C Объектно-ориентированный Использует сообщения Динамический Протоколы Интроспекция.
Objective-C Memory management Memory management is semi-automatic: The programmer must allocate memory for objects either a) explicitly (alloc) or b) indirectly.
I/O and Data Formatting Introduction to Class Concepts INFSY 307 Spring 2003 Lecture 3.
Course Summary Xcode & iPhone Simulator
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
Lecture 19 CIS 208 Wednesday, April 06, Welcome to C++ Basic program style and I/O Class Creation Templates.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Computer Science 111 Fundamentals of Computer Programming I Working with our own classes.
Lecture 06 Java and OOP Jaeki Song. Outlines Java and OOP –Class and Object – Inheritance – Polymorphism.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
OOP with Objective-C Categories, Protocols and Declared Properties.
Persistence CS 344 Mobile App Development Robert Muller.
1 CS161 Introduction to Computer Science Topic #16.
CS Class 19 Today  Practice with classes Announcements  Turn in algorithm for Project 5 in class today  Project 5 due 11/11 by midnight – .
1 Programming Principles II Lecture Notes 4 Functions (Returning Values) Andreas Savva.
More Objective-C Details FA 172 Intro to Mobile App Development.
Introduction to Objective-C Spring Goals An introduction to Objective-C As implemented by the Apple LLVM Compiler 4.0 (a.k.a. Clang) Only the basics…
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
1 Reverse a String iPhone/iPad, iOS Development Tutorial.
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.
Classes, Interfaces and Packages
DCS 2133 Object Oriented Programming Defining Your Own Classes Part 2.
Learning & Development Mobile apps for iPhone & iPad.
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.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
CS116 SENEM KUMOVA METİN. Outline What is C++ ? Some features of C++ Input and Output Operations Manipulators C++ header files Namespaces and scope resolution.
2-Oct-16 Basic Object-Oriented Concepts. 2 Concept: An object has behaviors In old style programming, you had: data, which was completely passive functions,
Yan Shi CS/SE 2630 Lecture Notes
CSC 205 Java Programming II
Chapter 3 L7.
CS212: Object Oriented Analysis and Design
Presentation transcript:

CS 3800 Su 11 Beg. IOS Dev L4 Obj C part 1 CS 3800 Introduction to IOS programming Summer 2011 G. Zimmerman

CS 3800 Su 11 Beg. IOS Dev Announcements Survey says… passwords 016 Keys: Server? Today’s ‘Final’ code will be posted after class L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Objective-C Goal: cover enough fundamentals to form a backdrop for understanding iOS programming. If you continue with iOS, you will want to delve further. L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Objective-C alloc init ivars and functions Multiple parameters Property, Synthesize L4 Obj C part 1 Memory management Protocols Categories Inheritance

CS 3800 Su 11 Beg. IOS Dev Objective-C Classes NSObject NSArray NSString NSSet NSDictionary NSDate Mutable & Immutable L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev l4 Obj-C part I Monday: A Fraction Class References: Objective C Beginner's guide RH CSSE 493 Podcast #8 proquest.safaribooksonline.com.mauric e.bgsu.edu/book/programming/objective -c/

CS 3800 Su 11 Beg. IOS Dev l4 Obj-C part I XCode: MacOS command line template Tour

CS 3800 Su 11 Beg. IOS Dev l4 Obj-C part I Format specifiers Google “C format specifiers” Like iomanip Appl: creating strings & general output Create a “format template” XX.XX 5 total spaces, 2 decimals –%5.2f Aside

CS 3800 Su 11 Beg. IOS Dev l4 Obj-C part I Format Example float x = ; int age = 145; char* cname = "old style c string"; print spec examples: 7.6f %7.6f ", x); print spec examples: 5.2f %5.2f ", x); print spec examples: 4.2f %4.2f ", x); print spec examples: 3.2f %3.2f ", x); name: %s, age:%4d", cname, age);

CS 3800 Su 11 Beg. IOS Dev l4 Obj-C part I Specifier Sampler Integer %I or %d Float %f %lf Char %c C-string %s

CS 3800 Su 11 Beg. IOS Dev C++ Fraction Class (partial) Recall from C++: class Fraction { public: Fraction(); Fraction( int, int); Fraction(int); private: int num, den; void normalize(); } L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Example: L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Designated initializer -(id) initFractionWithNumerator:(NSInteger) aNumerator denominator:(NSInteger) aDenominator { self = [super init]; if ( self != nil) { ", __FUNCTION__); numerator = aNumerator; denominator = aDenominator; } return self; } L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev description #pragma mark – #pragma mark NSObject overrides (NSString *) description { if ( denominator ==1 ) return [NSString numerator]; //else return FILL IN THE BLANK ; } L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Make some fractions #import [ [ classname alloc ] init] Retain count L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Standard representation -(void) normalize { if ( denominator <0) { numerator = -numerator; denominator = -denominator; } int a = abs(numerator); int b= abs(denominator); int t; while (b != 0) { t = b; b = a % b; a = t;} // a is the gcd numerator = numerator / a; denominator = denominator / a; } L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Revised initializer -(id) initFractionWithNumerator:(NSInteger)aNum denominator:(NSInteger)aDen { if ( aDen == 0) return nil; self = [super init]; if ( self != nil ) { numerator = aNum; denominator = aDen; } [self normalize]; return self; } L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Alternate initializers Convenience for clients Reuse designated intializer Whole number initWithWholeNumber: Default initializer: Init –For Default behavior L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev CLASS convenience methods Fraction *fx = [FRACTION zero]; Standard is to return an autoreleased object +(id) zero; +(id) one; +(id) negativeOne; +(id) fractionWithNumerator:(NSInteger)num denominator:(NSInteger)two; L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Retain Counts (intro) Onbject: many owners. i.e. Many pointers to the one object. Fraction *x = [Fraction one]; Fraction *y = x; [y retain]; Fraction *z = y; [z retain]; L4 Obj C part 1 numerator: 1 denominator: 1 x y z

CS 3800 Su 11 Beg. IOS Dev Memory management Cardinal Rules L4 Obj C part 1 Only release or autorelease objects you own. You own it if: it was created with a method whose name begins: alloc new copy ( a few more) you send it a retain message.

CS 3800 Su 11 Beg. IOS Dev C++ getters/setters class Fraction { public: void setNumerator( int ); int getNumerator(); private: int num, den; void normalize(); } Fraction x; x.setNumerator(2); cout << “ The num is” << x.getNumerator(); L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Objective C getters/setters Getters: (NSInteger) numerator { return numerator; } Setter: -(void) setNumerator { // spelling important ? } L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Dot Notation 1 Fraction * f1 = ….. NSInteger top = [f1 numerator]; //getter OR NSInteger top = f1.numerator; // calls the getter f1.numerator IS [f1 numerator]; THIS IS NOT YOUR FATHER’S dot Notation! L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Dot Notation 2 Fraction * f1 = ….. = [f1 setNumerator:14]; //setter OR f1.numerator = 14; // calls the setter Where did the Set go? L4 Obj C part 1

CS 3800 Su 11 Beg. IOS Dev Property & Synthesize  More than: Automatic setters/getters of iVars  Exposing state in a safe way (inc: subclassing). ( L4 Obj C part 1