Introductory ios Development
|
|
- Gladys Erin Simpson
- 6 years ago
- Views:
Transcription
1 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Introductory ios Development Unit 3 - Swift Classes Quick Links & Text References Structs vs. Classes Structs intended for simpler classes Few members/properties Few methods Structs are value types struct2 = struct1 creates and exact duplicate of struct1 Passed to functions by value (copy) Classes are reference types instance2 = instance1 creates two references to same object Passed to functions by reference Classes include: Inheritance, type casting, deinitializers Defining class YourClassName { var prop1 = 0 var prop2 = 0 Structs are the same expect replace class with struct Really no members. Members and properties are combined Setters and getters (basic) are built-in Referred to as stored properties (variable or constant) Defining Instances let myinstance = YourClassName() Since this is technically a pointer to an instance, the pointer is constant Page 1 of 19
2 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Accessing Properties Properties are public Can get and set Access via dot notation var newvalue = myinstance.prop1 myinstance.prop2 = newvalue Advanced topic: lazy properties, not initialized until actually used Initializers For structures: can send initial values for any property let myinstance = YourClassName(prop1: 10, prop2: 25) Note can even initialize values to stored properties declared let For classes define init( ) (not a function) Properties must be given a value either when declared (= ) or in the initializer Or, use optional types (?) to designate will assign value later init can be overloaded init() { firstname = ""; lastname = ""; init(first:string, last:string) { firstname = first; lastname = last; init(lastname:string, firstname:string) { self.firstname = firstname; self.lastname = lastname; Note can even have two functions with the same signature (init(string, String)) because parameter names distinguish them Parameters must have a name (used both internal and external). External names must be provided when invoking an initializer with parameters Unless you precede the parameter name with underscore designating you don t want to use an external name When parameters and properties have the same name, precede properties with self Page 2 of 19
3 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Computed Properties Defined as calculated properties Very flexible: can include both getters and setters Would guess setters rarely used var fullname:string { get { return firstname + " " + lastname set { //Code to split first and last If no setter (common, read-only) can leave off the get Computed properties must be explicitly typed See Computed Properties in book Property Observers Great for validation willset didset willset new value automatically named newvalue or can define parameter name in definition didset old value automatically name oldvalue or can define parameter name in definition class Something { var prop1:int { willset { if newvalue > 50 { //do something didset (mynamefornewvalue) { //do something Page 3 of 19
4 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Type Properties (Class Variables) Shared among all class instances Struct can have stored or computed type properties Class type properties must be computed For struct, add static to definition For class, add class to definition struct MyStruct { static var prop1 = 25 static var prop2:int { return anint class MyClass { class var prop1: Int { return anint Get at type properties same way as class variables: via the class/struct name println(mystruct.prop1) println(myclass.prop1) Can also be changed at run-time (if var) Built-In Classes As you ve already seen, ObjC has many built-in classes NSLog NSString NSDate NSArray NSMutableArray Many, many others Remember, the NS stands for NextStep. NextStep expanded on the C programming language. That language then progressed even more to become ObjC which is still progressing sign designates newer technology (ObjC) commands Remember the new technology array declarations and access. Page 4 of 19
5 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Methods See Unit 2: Swift Function Syntax for more details Instance methods have access to stored/computed properties Basically functions defined inside a class/struct Parameter names are both internal and external No # required on method parameters Also, type methods, that are called using the class/struct name. Called via the type name. Add class or static before func Access to type properties Inheritance Classes based on other classes class Subclass: Superclass { Superclass is the base class Subclass is a new class that uses Superclass as its foundation. Subclass inherits all the properties and methods of Superclass Subclass can have properties and methods of its own, effectively adding them to the Superclass Subclass can override the methods of the Superclass override func SomeFunc SomeFunc is defined in the super class, but this subclass overrides it with its own definition final prevents a subclass from overriding a property/method super is used to access the properties/methods of the superclass when they are overridden Subclasses can be used as a base class class AnotherSubclass: Subclass { AnotherSubclass has access to all the properties and methods of Subclass including the properties and methods of Superclass Good example (MediaItem) under Type Casting chapter in book Page 5 of 19
6 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Using Built-In Classes Messages Like all languages, ObjC classes contain methods that do things with the class members (instance variables) You ll learn to define your own class a little later in these notes. What s different is how these methods are invoked In most languages you call the method In ObjC you send the method a message Actually, object-oriented theory refers to sending a method a message so ObjC is more true to theory My summer ios instructor considers messaging one of the most confusing concepts in ObjC (at least for beginners) Here s an example: NSDate *now = [NSDate date]; This command creates (instantiates) a new NSDate object now is a pointer to that object. Remember all object variables are actually pointers. The square brackets designate a message to the class The first element of the message is the receiver The receiver can either be a class or an instance (variable) of that class type Like other languages, ObjC can have class methods and instance methods You message class methods using the class name You message instantiation methods using (object, instance) variables This example references a class name (NSDate) so it is messaging a class method The most common type of class method is the constructor This example sends a message to the constructor telling it to create a new NSDate object, initializes it to the current date/time In other languages date might appear in parentheses Finally, now is set to point to the new object Instantiate an NSDate. Note the different options (try datewithnaturallanguages tring) NSDateFormatter *myformat = [[NSDateFormatter alloc] init]; [myformat MM/dd/yyyy ; NSLog(@ Date %@, [myformat stringfromdate:adate]); Page 6 of 19
7 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Here s another example from the Unit 2 notes if([city isequal:@"plover"]) Here, a message is being sent to city This is an instantiation method because city is a NSString variable (more technically a pointer to an NSString instantiation) The isequal method is being called. isequal requires (at least) one parameter (in this case, what city should be compared to) Note the parameter value is separated from the method name by a colon. Parentheses are not used. Another example NSLog(@"%@", city); Actually, I lied this is NOT a message. NSLog is actually a function. How can you tell? No square brackets parentheses instead How do you keep them straight practice Final example (for now) NSLog(@"%@", [CSZ substringwithrange:nsmakerange(15,9)]); Here the NSLog function is called with two arguments The first argument is the formatting The second argument is a message (note square brackets) to the substringwithrange method for CSZ. To determine the appropriate range, the NSMakeRange function is called with two arguments The substringwithrange method returns a (sub)string that is used as the second parameter WHEW! Some methods (those that return values) can now be called using dot-notation mynsarray.count and [mynsarray count] are both legal Only way to tell is to try the dot notation. If it doesn t work, switch to messaging. Page 7 of 19
8 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Defining Your Own Classes To add a class to your project, first click the file below which you want the new class files to appear (main.m?) You can move them later if you wish FileNewFile, OS X, Cocoa, Objective-C class Give the class a name Start the class with your initials, UPPERCASE Optional, but recommended This prevents conflicts between your personal classes and the built-in classes TitleCase after that Subclass (for us) is always NSObject Subclass is the class this class is based on Designate the project folder (probably current project) Create the OldCube class ObjC classes are stored in two separate files The.h (header) files contains interface information for this class (how other classes communication with it) and member definitions Actually, ObjC experts don t use the term, member, they use the more generic/accurate instance variable I ll use instance variable from now on. The.m (ObjC) file contains methods of the class Header file (.h) Imports the Foundation class library which includes the C and ObjC extensions Declares the class (@interface) Names the class Designates that it s based on NSObject Inherits all the methods of a generic object Class file (.m) Imports/links to the header (.h) file for this class Includes an implementation region You enter the (private) class code here Page 8 of 19
9 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Defining Instance Variables In.h file surrounded by curly brackets Just like ObjC variables All instance variables are hidden inaccessible from outside the class Accessor Methods To allow programs and other classes to access the instance variables, you define accessor methods Setter and getter methods just like other languages You first have to define the prototypes (or interfaces) for these methods in the.h file Add height, width, depth instance variables Define VFGRectangle : NSObject { float height; float width; - (float) height; - (void) setheight:(float) h; - (float) width; - (void) setwidth:(float) Page 9 of 19
10 Instructor s Introductory ios Development Unit 3 - Objective-C Classes The minus sign in front of each prototype designates the method as an instance method Later you ll also see a plus sign. That designates a class method (shared by all instances of the class). The first prototype (in each pair) is for the getter. (int) designates the type of variable to be returned. The type returned by the getter must match the instance variable type Note the name of the getter method is the same as the instance variable name ObjC tradition (not required though) The second prototype is the setter Setters typically return void The setter name is typically the same as the getter name with the word set on the front Technically, the method name also includes the colon (more on that later) Setters always have one parameter the new value for the instance variable After a colon, the parameter type and name must be specified Parameter name cannot be the same as an instance variable name The actual code for the methods is placed in the.m file Code accessors #import VFGRectangle - (float)height { return height; - (void)setheight:(float)h { height = Page 10 of 19
11 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Note both method names are identical to the prototypes in the.h file As in most languages, the getter simply returns the appropriate instance variable value The setter in this simple example simply transfers the parameter value to the appropriate instance variable Xcode intellisense will often help you complete the method. Press enter when the appropriate command appears an intellisense will complete the rest of the line More advanced setters will typically do validation before updating the instance variable value Objective-C Properties The newest versions of ObjC include properties that make creating instance variables and their accessors much easier. Define a Cube VFGRectangle : float float width; - Page 11 of 19
12 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Note the instance variables and the accessors have been replaced statements Also note the curly brackets are gone Instance variables are automatically created, but the (hidden) variables include an underscore at the beginning _height _width Note both the simple setter and getter are also replaced by statements. If you need to do validation in the setter, you ll have to define your own setter like the one above. Finally, note I ve added a prototype for a new method called calcarea This method will calculate the area of the rectangle based on the current instance variable values This method has no parameters, but remember if there are parameters, ObjC doesn t use parentheses like other languages it uses a colon (see setters above). Now let s take a look at the.m file Declare height, width, depth properties. Declare calcvolume Declare VFGRectangle - (float)calcarea { //Calc area Um, where are the definitions of the setters and getters Not needed Default setters and getters already defined Since calcarea is not a property, we have to provide the implementation method Remember, unlike functions, methods don t surround parameters with parentheses The minus sign designates this as an instance method Page 12 of 19
13 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Pay attention that if you implement both the accessor methods for a property yourself, the compiler will assume that you are taking control of the property and won t create the instance variable for you. If you still need it, you need to declare it yourself in the class propertyname = _instvarname; Using self in a Class To finish up our basic class, we need to code the calcarea method Write methods for calcvolume and calcsurfacearea - (float)calcarea { return self.height * self.width; //return [self height] * [self width]; //return _height * _width; Page 13 of 19
14 Instructor s Introductory ios Development Unit 3 - Objective-C Classes First note the last, commented out, line. This works. The command accesses the instance variables directly, multiplies them, and returns the result However, It is good Object-Oriented practice to always use accessor methods if you have them. (Knapp) In the past, I ve taught that you should always use instance variables, assuming they should process faster than accessors. Though that may be true, I ve since learned that compilers have optimizers that actually modify your code to make it more efficient. I ve been told the optimizer will do a much better job than I could do myself. So, now I let the optimizer decide whether to use the accessor or the instance variable. The first commented out line sends messages to the current instance of the class self The messages call the (automatically created) getters for height and width The values returned by the getters are multiplied and the results are returned. The actual return statement uses the latest ObjC technology (dot notation) to access the property values. Using dot notation also sends a message to the getter, just using different syntax. Creating Constructors Most classes include constructors that define how the class instance variables should be initiated when the class is instantiated. If you don t define one, ObjC uses a default constructor that basically sets all the instance variables to nil. Basic constructor header (.h) -(id)init; In Cube, declare a 0- parameter constructor id is the ObjC type of a generic object The return type of the method must be surrounded by parentheses Constructor is typically named init Page 14 of 19
15 Instructor s Introductory ios Development Unit 3 - Objective-C Classes Basic constructor method (.m) -(id)init { if(!self = [super init]) return nil; self.height = 0; self.width = 0; return self; First instantiate the super class If the super class instantiation worked Set instance variable initial values Return pointer to new object Write the constructor initializing all instance variables to 0 Parameter Constructor header (.h) -(id)initwithheight:(float)height Width:(float)width; See Methods with More than one Parameter below Note spacing and capitalization Convention only Parameter Constructor method (.m) -(id)initwithheight:(float)height Width:(float)width{ self = [super init]; if(self) { self.height = height; self.width = width; //end if return self; Pretty much the same as basic constructor but parameters are used as initial values. Declare constructor with 3 parameters Write constructor Putting the Class to Work Now that we ve created the class we ll want to instantiate it and put it to good use. The following example code would be found in main.m, but you could instantiate the class from just about anywhere. Import Cube.h Instantiate Cube with no parameters. Use dot notation in initialize Page 15 of 19
16 Instructor s Introductory ios Development Unit 3 - Objective-C Classes #import <Foundation/Foundation.h> #import "VFGRectangle.h" int main(int argc, const char * argv[]) { VFGRectangle *arectangle = [[VFGRectangle alloc] init]; //Old way [arectangle setheight:10.5]; [arectangle setwidth:100]; NSLog(@"Area is %.2f", [vrect calcarea]); //Area is //New way arectangle.height = 10.5; arectangle.width = 100; NSLog(@"Area is %.2f", vrect.calcarea); //Area is //Initialize with parameters VFGRectangle *arectangle = [[VFGRectangle alloc] initwithheight:10.5 Width:100]; NSLog(@"Area is %.2f", vrect.calcarea); //Area is Page 16 of 19
17 Instructor s Introductory ios Development Unit 3 - Objective-C Classes First we have to link main.m to the class. The #import statement does that. Note because we re linking to a custom class, not a built-in class library, we use quotes instead of angle brackets. Next we instantiate our class The name of the class is used as the variable type The variable name includes a star. All object variables must be pointers. The second half of the statement allocates memory for the class and calls the init method to initialize it. alloc is a method of the class NSObject, which is the root class from which all the Objective-C classes inherit. This method takes care to allocate the memory to contain the object, and it also cleans the memory so it won t contain garbage. Remember if you don t define an init method NSObject which our class is based on has a standard init method. [[class alloc] init] is so common, NSObject has a shortcut: [class new] Then, we have to get some data into the class. First, the old ObjC way, using messages Send a message to arectangle (instance of VFGRectangle), invoking setter for height, sending a value of 10.5 Send a message to arectangle invoking setter for width, sending a value of 100 Send a message to arectangle, invoking the calcarea method and display the returned value. Page 17 of 19
18 Instructor s Introductory ios Development Unit 3 - Objective-C Classes The latest (very recent) versions of ObjC allow you to dot notation to invoke class methods. These should look very familiar from other languages you may know. Note ObjC purists aren t real thrilled with the new dot notation. That s why I show you both ways. You ll likely see many online examples using the old way. Again, the compiler s optimizer should make either version as efficient as possible. Display the volume and surface area Methods with More than One Parameter Remember, when a method includes a parameter, you include the parameter after a colon Technically, the colon is part of the method name Instantiate with three parameters. - (void) setwidth:(float) thewidth; When methods have more than one parameter things get more complicated (or at least more confusing) Let s say we need a method that accepts (sets) values for both width and height. I m not sure of its usefulness, but let s go with it. Here s what the prototype (.h file) might look like - (void) setwidth:(float)thewidth height:(float)theheight; The second parameter (float)theheight kind of makes sense Type float, parameter name theheight But what s with the height before the colon. ObjC designates this the parameter s label setwidth is actually the label of the first parameter The labels combined form the method s name Method name = setwidth:height: Remember the colons are always part of the method name Bizarre The implementation of setwidth:height: would look pretty much the same Page 18 of 19
19 Instructor s Introductory ios Development Unit 3 - Objective-C Classes - (void) setwidth:(float)thewidth Height:(float)theHeight { _width = thewidth; _height = theheight; //Or //self.width = thewidth; //self.height = theheight; //Or //[self setwidth:thewidth]; //[self setheight:theheight]; Note we transfer the parameters (by name) to the appropriate instance variables (assuming property use here) Alternatively, you could invoke the setter methods assuming they exist as well. Calling (messaging) a method that has more than one parameter [arectangle setwidth:10 height:20]; The good news is even though the colons are part of the method name, they are always followed by a value The advantage of this technique is the parameters are clearly labeled. You can t confuse the order of the parameters (obvious that width comes first, then height). You may not however reverse the parameters (height then width) even though they are labeled. If there are more than 2 parameters, simply repeat the pattern. Singletons ios Summer 2013 Day 4 Resource Page 19 of 19
Mobile Application Programming. Swift Classes
Mobile Application Programming Swift Classes Swift Top-Level Entities Like C/C++ but unlike Java, Swift allows declarations of functions, variables, and constants at the top-level, outside any class declaration
More informationIntroductory ios Development
Introductory ios Development 152-164 Unit 2 - Basic Objective-C Syntax Quick Links & Text References Console Application Pages Running Console App Pages Basic Syntax Pages Variables & Types Pages Sequential
More informationObjective-C. Stanford CS193p Fall 2013
New language to learn! Strict superset of C Adds syntax for classes, methods, etc. A few things to think differently about (e.g. properties, dynamic binding) Most important concept to understand today:
More informationMobile Application Programming. Swift Classes
Mobile Application Programming Swift Classes Swift Objects Classes, structures, and enums are all object types with different defaults in usage Classes are reference types that share the same object when
More informationCS193p Spring 2010 Thursday, April 29, 2010
CS193p Spring 2010 Announcements You should have received an e-mail by now If you received e-mail approving enrollment, but are not in Axess, do it! If you have any questions, please ask via e-mail or
More informationCS193P - Lecture 3. iphone Application Development. Custom Classes Object Lifecycle Autorelease Properties
CS193P - Lecture 3 iphone Application Development Custom Classes Object Lifecycle Autorelease Properties 1 Announcements Assignments 1A and 1B due Wednesday 1/13 at 11:59 PM Enrolled Stanford students
More informationDesign Phase. Create a class Person. Determine the superclass. NSObject (in this case)
Design Phase Create a class Person Determine the superclass NSObject (in this case) 8 Design Phase Create a class Person Determine the superclass NSObject (in this case) What properties should it have?
More informationMobile Application Development
Mobile Application Development Lecture 13 Introduction to ObjectiveC Part II 2013/2014 Parma Università degli Studi di Parma Lecture Summary Object creation Memory management Automatic Reference Counting
More informationQuestions. Exams: no. Get by without own Mac? Why ios? ios vs Android restrictions. Selling in App store how hard to publish? Future of Objective-C?
Questions Exams: no Get by without own Mac? Why ios? ios vs Android restrictions Selling in App store how hard to publish? Future of Objective-C? Grading: Lab/homework: 40%, project: 40%, individual report:
More informationObject Oriented Design
Object Oriented Design Lecture 3: Introduction to C++ (Continue) Examples using declarations that eliminate the need to repeat the std:: prefix 1 Examples using namespace std; enables a program to use
More informationMobile Application Development
Mobile Application Development Lecture 12 Introduction to ObjectiveC 2013/2014 Parma Università degli Studi di Parma Lecture Summary ObjectiveC language basics Classes and objects Methods Instance variables
More informationIPHONE DEVELOPMENT. Getting Started with the iphone SDK
IPHONE DEVELOPMENT Getting Started with the iphone SDK OBJECTIVE-C The Big Picture STRICT SUPERSET OF C The Objective C Language Any C stuff applies Standard libs are here (time, sqrt etc) The C Language
More informationITP 342 Mobile App Dev. Fundamentals
ITP 342 Mobile App Dev Fundamentals Objective-C Classes Encapsulate data with the methods that operate on that data An object is a runtime instance of a class Contains its own in-memory copy of the instance
More informationStanford CS193p. Developing Applications for ios Fall Stanford CS193p. Fall 2013
Developing Applications for ios -14 Today What is this class all about? Description Prerequisites Homework / Final Project ios Overview What s in ios? MVC Object-Oriented Design Concept Objective C (Time
More informationCS193E Lecture #3 Categories and Protocols Cocoa Memory Management
CS193E Lecture #3 Categories and Protocols Cocoa Memory Management Winter 2008, Dempsey/Marcos 1 Today s Topics Questions from Assignment 1A or 1B? Categories Protocols Cocoa Memory Management Object life
More informationChapter 11. Abstract Data Types and Encapsulation Concepts ISBN
Chapter 11 Abstract Data Types and Encapsulation Concepts ISBN 0-321-49362-1 Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language
More information(infinitespeak.wordpress.com) Classes and Structs. Dr. Sarah Abraham
(infinitespeak.wordpress.com) Classes and Structs Dr. Sarah Abraham University of Texas at Austin CS329e Fall 2018 Classes and Structures General-purpose, flexible constructs to build blocks of code Properties
More informationObject-Oriented Programming with Objective-C. Lecture 2
Object-Oriented Programming with Objective-C Lecture 2 Objective-C A Little History Originally designed in the 1980s as a fusion of Smalltalk and C Popularized by NeXTSTEP in 1988 (hence the ubiquitous
More informationAnnouncement. Final Project Proposal Presentations and Updates
Announcement Start Final Project Pitches on Wednesday Presentation slides dues by Tuesday at 11:59 PM Email slides to cse438ta@gmail.com Extensible Networking Platform 1 1 - CSE 438 Mobile Application
More informationITP 342 Advanced Mobile App Dev. Memory
ITP 342 Advanced Mobile App Dev Memory Memory Management Objective-C provides two methods of application memory management. 1. In the method described in this guide, referred to as manual retain-release
More informationCS-202 Introduction to Object Oriented Programming
CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction
More informationiphone Application Programming Lecture 3: Swift Part 2
Lecture 3: Swift Part 2 Nur Al-huda Hamdan RWTH Aachen University Winter Semester 2015/2016 http://hci.rwth-aachen.de/iphone Review Type aliasing is useful! Escaping keywords could be useful! If you want
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationData Structures (list, dictionary, tuples, sets, strings)
Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access
More informationMobile Application Programming. Objective-C Classes
Mobile Application Programming Objective-C Classes Custom Classes @interface Car : NSObject #import Car.h + (int) viper; - (id) initwithmodel:(int)m; @implementation Car Point position; float velocity;
More informationOverview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017
Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable
More informationAbstract data types &
Abstract Data Types & Object-Oriented Programming COS 301 - Programming Languages Chapters 11 & 12 in the book Slides are heavily based on Sebesta s slides for the chapters, with much left out! Abstract
More informationAbstract Data Types & Object-Oriented Programming
Abstract Data Types & Object-Oriented Programming COS 301 - Programming Languages Chapters 11 & 12 in the book Slides are heavily based on Sebesta s slides for the chapters, with much left out! Abstract
More informationReview (Basic Objective-C)
Classes Header.h (public) versus Implementation.m (private) @interface MyClass : MySuperclass... @end (only in header file) @interface MyClass()... @end (only in implementation file) @implementation...
More informationPrinciples of Programming Languages. Objective-C. Joris Kluivers
Principles of Programming Languages Objective-C Joris Kluivers joris.kluivers@gmail.com History... 3 NeXT... 3 Language Syntax... 4 Defining a new class... 4 Object identifiers... 5 Sending messages...
More informationObjective-C. Deck.m. Deck.h. Let s look at another class. This one represents a deck of cards. #import <Foundation/Foundation.h> #import "Deck.
Deck.h #import @interface Deck : NSObject @interface Deck() @implementation Deck Deck.m Let s look at another class. This one represents a deck of cards. Deck.h #import
More informationReview. iphone Application Programming Lecture 2: Objective-C, Cocoa. History. Objective-C. Device restrictions. Interaction paradigm changes
Review iphone Application Programming Lecture 2: Objective-C, Cocoa Device restrictions Gero Herkenrath Media Computing Group RWTH Aachen University Winter Semester 2013/2014 http://hci.rwth-aachen.de/iphone
More informationLecture 10: building large projects, beginning C++, C++ and structs
CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 10:
More informationLesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014
Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class
More informationCS304 Object Oriented Programming Final Term
1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing
More informationConstructors for classes
Constructors for Comp Sci 1570 Introduction to C++ Outline 1 2 3 4 5 6 7 C++ supports several basic ways to initialize i n t nvalue ; // d e c l a r e but not d e f i n e nvalue = 5 ; // a s s i g n i
More informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationChapter 11. Abstract Data Types and Encapsulation Concepts
Chapter 11 Abstract Data Types and Encapsulation Concepts Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language Examples Parameterized
More informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationPorting Objective-C to Swift. Richard Ekle
Porting Objective-C to Swift Richard Ekle rick@ekle.org Why do we need this? 1.2 million apps in the ios App Store http://www.statista.com/statistics/276623/numberof-apps-available-in-leading-app-stores/
More informationiphone Application Programming Lecture 3: Swift Part 2
Lecture 3: Swift Part 2 Nur Al-huda Hamdan RWTH Aachen University Winter Semester 2015/2016 http://hci.rwth-aachen.de/iphone Properties Properties are available for classes, enums or structs Classified
More informationModule 10 Inheritance, Virtual Functions, and Polymorphism
Module 10 Inheritance, Virtual Functions, and Polymorphism Table of Contents CRITICAL SKILL 10.1: Inheritance Fundamentals... 2 CRITICAL SKILL 10.2: Base Class Access Control... 7 CRITICAL SKILL 10.3:
More informationiphone Programming Patrick H. Madden SUNY Binghamton Computer Science Department
iphone Programming Patrick H. Madden SUNY Binghamton Computer Science Department pmadden@acm.org http://optimal.cs.binghamton.edu General Outline Overview of the tools, and where to get more information
More informationChapter 11. Abstract Data Types and Encapsulation Concepts
Chapter 11 Abstract Data Types and Encapsulation Concepts Chapter 11 Topics The Concept of Abstraction Introduction to Data Abstraction Design Issues for Abstract Data Types Language Examples Parameterized
More informationCpt S 122 Data Structures. Introduction to C++ Part II
Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function
More informationMakefiles Makefiles should begin with a comment section of the following form and with the following information filled in:
CS 215 Fundamentals of Programming II C++ Programming Style Guideline Most of a programmer's efforts are aimed at the development of correct and efficient programs. But the readability of programs is also
More informationFor your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to
For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to access them. Contents at a Glance About the Author...
More informationAn Introduction to C++
An Introduction to C++ Introduction to C++ C++ classes C++ class details To create a complex type in C In the.h file Define structs to store data Declare function prototypes The.h file serves as the interface
More informationOOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.
OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.
More informationChapter 5 Object-Oriented Programming
Chapter 5 Object-Oriented Programming Develop code that implements tight encapsulation, loose coupling, and high cohesion Develop code that demonstrates the use of polymorphism Develop code that declares
More informationCOSC 2P95. Procedural Abstraction. Week 3. Brock University. Brock University (Week 3) Procedural Abstraction 1 / 26
COSC 2P95 Procedural Abstraction Week 3 Brock University Brock University (Week 3) Procedural Abstraction 1 / 26 Procedural Abstraction We ve already discussed how to arrange complex sets of actions (e.g.
More informationCOP 3330 Final Exam Review
COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time
More informationObjective-C ICT/7421ICTNathan. René Hexel. School of Information and Communication Technology Griffith University.
Objective-C 2.0 2501ICT/7421ICTNathan René Hexel School of Information and Communication Technology Griffith University Semester 1, 2012 Outline Fast Enumeration and Properties 1 Fast Enumeration and Properties
More informationG52CPP C++ Programming Lecture 9
G52CPP C++ Programming Lecture 9 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture const Constants, including pointers The C pre-processor And macros Compiling and linking And
More informationPIC 10A Objects/Classes
PIC 10A Objects/Classes Ernest Ryu UCLA Mathematics Last edited: November 13, 2017 User-defined types In C++, we can define our own custom types. Object is synonymous to variable, and class is synonymous
More informationChapter 1 Getting Started
Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different
More informationComputer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring Topic Notes: C and Unix Overview
Computer Science 2500 Computer Organization Rensselaer Polytechnic Institute Spring 2009 Topic Notes: C and Unix Overview This course is about computer organization, but since most of our programming is
More informationios: Objective-C Primer
ios: Objective-C Primer Jp LaFond Jp.LaFond+e76@gmail.com TF, CS76 Announcements n-puzzle feedback this week (if not already returned) ios Setup project released Android Student Choice project due Tonight
More informationComputer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview
Computer Science 322 Operating Systems Mount Holyoke College Spring 2010 Topic Notes: C and Unix Overview This course is about operating systems, but since most of our upcoming programming is in C on a
More informationObjective-C and Cocoa User Guide and Reference Manual
Objective-C and Cocoa User Guide and Reference Manual Version 7.1 Copyright and Trademarks LispWorks Objective-C and Cocoa Interface User Guide and Reference Manual Version 7.1 March 2017 Copyright 2017
More informationWorking with Objects. Overview. This chapter covers. ! Overview! Properties and Fields! Initialization! Constructors! Assignment
4 Working with Objects 41 This chapter covers! Overview! Properties and Fields! Initialization! Constructors! Assignment Overview When you look around yourself, in your office; your city; or even the world,
More informationOBJECT ORİENTATİON ENCAPSULATİON
OBJECT ORİENTATİON Software development can be seen as a modeling activity. The first step in the software development is the modeling of the problem we are trying to solve and building the conceptual
More informationCS193E: Temperature Converter Walkthrough
CS193E: Temperature Converter Walkthrough The goal of this walkthrough is to give you a fairly step by step path through building a simple Cocoa application. You are encouraged to follow the walkthrough,
More informationCS 32. Lecture 2: objects good?
CS 32 Lecture 2: objects good? Double Vision This course has two main tracks Unix/shell stuff Object-Oriented Programming Basic C++ familiarity Off by one! Another Troika This class has three main texts
More informationC++ (classes) Hwansoo Han
C++ (classes) Hwansoo Han Inheritance Relation among classes shape, rectangle, triangle, circle, shape rectangle triangle circle 2 Base Class: shape Members of a class Methods : rotate(), move(), Shape(),
More informationObject-Oriented Programming in Objective-C
In order to build the powerful, complex, and attractive apps that people want today, you need more complex tools than a keyboard and an empty file. In this section, you visit some of the concepts behind
More information(5 2) Introduction to Classes in C++ Instructor - Andrew S. O Fallon CptS 122 (February 7, 2018) Washington State University
(5 2) Introduction to Classes in C++ Instructor - Andrew S. O Fallon CptS 122 (February 7, 2018) Washington State University Key Concepts Function templates Defining classes with member functions The Rule
More informationWeek 8: Operator overloading
Due to various disruptions, we did not get through all the material in the slides below. CS319: Scientific Computing (with C++) Week 8: Operator overloading 1 The copy constructor 2 Operator Overloading
More informationInheritance, Polymorphism, and Interfaces
Inheritance, Polymorphism, and Interfaces Chapter 8 Inheritance Basics (ch.8 idea) Inheritance allows programmer to define a general superclass with certain properties (methods, fields/member variables)
More informationOperator overloading
1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The
More informationObjective-C and COCOA Applications
Objective-C and COCOA Applications Fall, 2012 Prof. Massimiliano "Max" Pala pala@nyu.edu Overview X-Code IDE Basics Objective-C Classes Methods Invocations Important Types Memory Management Protocols Exceptions
More information1.The basics 5 Comments 5 Variables and basic types 6 Operators 8 Object variables 10 A note on prefixes and namespaces 11
1.The basics 5 Comments 5 Variables and basic types 6 Operators 8 Object variables 10 A note on prefixes and namespaces 11 2.Branching and decisions 12 If-else statement 12 Switch statement 13 Ternary
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationOVERVIEW. Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net
OVERVIEW Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net Microsoft MVP for 4 years C#, WinForms, WPF, Silverlight Joined Cynergy about
More informationCS 47. Beginning iphone Application Development
CS 47 Beginning iphone Application Development Introductions Who, why, which? Shameless Plug: LoudTap Wifi Access (If it works..) SSID: Stanford Username/password: csp47guest Expectations This is a programming
More informationMARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012
MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)
More informationStanford CS193p. Developing Applications for ios. Winter CS193p! Winter 2015
Stanford CS193p Developing Applications for ios Today More Swift & the Foundation Framework Optionals and enum Array, Dictionary, Range, et. al. Data Structures in Swift Methods Properties Initialization
More informationAdvanced Object-Oriented Programming. 11 Features. C# Programming: From Problem Analysis to Program Design. 4th Edition
11 Features Advanced Object-Oriented Programming C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition Chapter Objectives Learn the
More informationObjective-C Part 2 (ECS189H) Ken Joy Serban Porumbescu
Objective-C Part 2 (ECS189H) Ken Joy joy@cs.ucdavis.edu Serban Porumbescu porumbes@cs.ucdavis.edu Today Objective-C Memory Management Properties Categories and Protocols Delegates Objective-C Memory Management
More informationInheritance and Polymorphism
Object Oriented Programming Designed and Presented by Dr. Ayman Elshenawy Elsefy Dept. of Systems & Computer Eng.. Al-Azhar University Website: eaymanelshenawy.wordpress.com Email : eaymanelshenawy@azhar.edu.eg
More informationQUIZ How do we implement run-time constants and. compile-time constants inside classes?
QUIZ How do we implement run-time constants and compile-time constants inside classes? Compile-time constants in classes The static keyword inside a class means there s only one instance, regardless of
More informationCE221 Programming in C++ Part 1 Introduction
CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationDeclaration Syntax. Declarations. Declarators. Declaration Specifiers. Declaration Examples. Declaration Examples. Declarators include:
Declarations Based on slides from K. N. King Declaration Syntax General form of a declaration: declaration-specifiers declarators ; Declaration specifiers describe the properties of the variables or functions
More informationIntroduction to Classes
Introduction to Classes Procedural and Object-Oriented Programming Procedural and Object-Oriented Programming Procedural programming focuses on the process/actions that occur in a program Object-Oriented
More informationG52CPP C++ Programming Lecture 7. Dr Jason Atkin
G52CPP C++ Programming Lecture 7 Dr Jason Atkin 1 This lecture classes (and C++ structs) Member functions inline functions 2 Last lecture: predict the sizes 3 #pragma pack(1) #include struct A
More informationJava How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;
More informationPROGRAMMING LANGUAGE 2
31/10/2013 Ebtsam Abd elhakam 1 PROGRAMMING LANGUAGE 2 Java lecture (7) Inheritance 31/10/2013 Ebtsam Abd elhakam 2 Inheritance Inheritance is one of the cornerstones of object-oriented programming. It
More informationCLASSES AND OBJECTS IN JAVA
Lesson 8 CLASSES AND OBJECTS IN JAVA (1) Which of the following defines attributes and methods? (a) Class (b) Object (c) Function (d) Variable (2) Which of the following keyword is used to declare Class
More informationInf1-OP. Inf1-OP Exam Review. Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein. March 20, School of Informatics
Inf1-OP Inf1-OP Exam Review Timothy Hospedales, adapting earlier version by Perdita Stevens and Ewan Klein School of Informatics March 20, 2017 Overview Overview of examinable material: Lectures Week 1
More informationAnd Even More and More C++ Fundamentals of Computer Science
And Even More and More C++ Fundamentals of Computer Science Outline C++ Classes Special Members Friendship Classes are an expanded version of data structures (structs) Like structs, the hold data members
More information22. Inheritance. Java. Summer 2008 Instructor: Dr. Masoud Yaghini
22. Inheritance Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Superclasses and Subclasses Using the super Keyword Overriding Methods The Object Class References Inheritance Object-oriented programming
More informationPREPARING FOR PRELIM 2
PREPARING FOR PRELIM 2 CS 1110: FALL 2012 This handout explains what you have to know for the second prelim. There will be a review session with detailed examples to help you study. To prepare for the
More informationCS102: Variables and Expressions
CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of
More informationIntroduction to C: Pointers
Introduction to C: Pointers Nils Moschüring PhD Student (LMU) Nils Moschüring PhD Student (LMU), Introduction to C: Pointers 1 1 Introduction 2 Pointers Basics Useful: Function
More informationITI Introduction to Computing II
ITI 1121. Introduction to Computing II Marcel Turcotte School of Electrical Engineering and Computer Science Inheritance Introduction Generalization/specialization Version of January 20, 2014 Abstract
More informationIn fact, as your program grows, you might imagine it organized by class and superclass, creating a kind of giant tree structure. At the base is the
6 Method Lookup and Constant Lookup As we saw in Chapter 5, classes play an important role in Ruby, holding method definitions and constant values, among other things. We also learned how Ruby implements
More informationModern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi
Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Move semantics Classes Operator overloading Making your class copyable Making your class movable Rule of all or nothing Inheritance
More informationObject Oriented Programming. Java-Lecture 11 Polymorphism
Object Oriented Programming Java-Lecture 11 Polymorphism Abstract Classes and Methods There will be a situation where you want to develop a design of a class which is common to many classes. Abstract class
More informationSwift. Introducing swift. Thomas Woodfin
Swift Introducing swift Thomas Woodfin Content Swift benefits Programming language Development Guidelines Swift benefits What is Swift Benefits What is Swift New programming language for ios and OS X Development
More information