Introduction to Objective-C and Xcode (Part 4) FA 175 Intro to Mobile App Development.

Slides:



Advertisements
Similar presentations
Table Views UITableView. Overview Table view basics Tables display lists of data Each item in a tables list is a row Tables can have an unlimited number.
Advertisements

Introduction to Arrays Chapter What is an array? An array is an ordered collection that stores many elements of the same type within one variable.
Class Relationships Part 1: Composition and Association CS 21a: Introduction to Computing I First Semester,
Arrays I Savitch Chapter 6.1: Introduction to Arrays.
Written by: Dr. JJ Shepherd
Chapter 10 Introduction to Arrays
Introduction to Objective-C and Xcode (Part 1) FA 175 Intro to Mobile App Development.
Programming with Collections Collections in Java Using Arrays Week 9.
ECE122 L13: Arrays of Objects March 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 13 Arrays of Objects.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
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.
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.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: String Manipulation
Sprite Animation CSE 391 Fall 2012 Tony Scarlatos.
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.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Chapter 10 Introduction to Components. Process Phases Discussed in This Chapter Requirements Analysis Design Implementation ArchitectureFramework Detailed.
Introduction to Objective-C and Xcode (Part 2) FA 175 Intro to Mobile App Development.
Introduction to Objective-C and Xcode (Part 3) FA 175 Intro to Mobile App Development.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Objective C Basics. It’s C with Some Extras!  Cross Platform language  Mac  Linux/UNIX  Windows  Layer above C (Superset)  Adds Object-Oriented.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
Data Structures and Java CS 105. L7: Java Slide 2 Data structure Data structure defined: A systematic way of organizing and accessing data Examples Dictionary:
Classes CS 21a: Introduction to Computing I First Semester,
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Java SE 8 for Programmers, Third Edition
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
Managing Multiple Views and Segues FA 172 Intro to Mobile App Development.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Create a Web View App Step-by-Step. Step 1 Create a new project in XCode using the "Single View Application" option.
+ An Intro To Xcode By Sarah Montroy. + What is Xcode?
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
Passing data between storyboard views Singleton pattern.
Introduction to Objective-C and Xcode (Part 5) FA 175 Intro to Mobile App Development.
CSC1401 Classes - 2. Learning Goals Computing concepts Adding a method To show the pictures in the slide show Creating accessors and modifiers That protect.
Scope When we create variables and functions, they are limited in where they are visible and where they can be referenced For the most part, the identifiers.
Course Summary Xcode & iPhone Simulator
Sounds, Images, and Text FA 172 Intro to Mobile App Development.
Chapter 4 Introduction to Classes, Objects, Methods and strings
Research Topics in Computational Science. Agenda Survey Overview.
Select (drop-down list) Inputs. Insert/Form/List Menu.
Structures and Classes Version 1.0. Topics Structures Classes Writing Structures & Classes Member Functions Class Diagrams.
OOP with Objective-C Categories, Protocols and Declared Properties.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter Array Basics.
More Objective-C Details FA 172 Intro to Mobile App Development.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
1 Reverse a String iPhone/iPad, iOS Development Tutorial.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Object Oriented Programming Session # 03.  Abstraction: Process of forming of general and relevant information from a complex scenarios.  Encapsulation:
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Arrays and Array Lists CS 21a. Problem 1: Reversing Input Problem: Read in three numbers and then print out the numbers in reverse order Straightforward.
Objective-C: Intro Michelle Alexander COMS E6998 2/4/2013.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Arrays. What is an array? An array is a collection of data types. For example, what if I wanted to 10 different integers? int num1; int num2; int num3;
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Using Procedures and Exception Handling
Implementing Classes Chapter 3.
Arrays and Array Lists CS 21a.
Classes CS 21a: Introduction to Computing I
Presentation transcript:

Introduction to Objective-C and Xcode (Part 4) FA 175 Intro to Mobile App Development

Agenda Complete the ProductInventoryApp project Class methods Arrays

ProductInventoryApp Instructions are posted on the course website Summary – Two view controllers (controlled by a navigation controller), one for the main interface, the other for the product – Product class included in the project – Three products created by main view controller – Detail/product view controller has its display based on a product object

ProductInventoryApp: main view No properties defined in ViewController.h file No outlet connections No action connections (button click functionality handled through the segues) Three product variables declared outside of the methods within the ViewController.m file (these could have been properties but there is no reason to have the data available as properties) Product objects created within viewDidload method (initialization code executed when view appears) prepareForSegue method checks which button was pressed (which segue was used) and then sets the appropriate product to be set by the second view

ProductInventoryApp: product view Separate class (with superclass UIViewController) had to be created and associated to this view controller Properties defined in.h file – outlet connections for all controls (except buttons) – One product object (to be set by the main view, but used by this view for display) Action connections (for the add and remove buttons) viewDidload contains code (in.m file) that displays details of product object property Code for the add/remove actions – Retrieve data from the text field and convert to int – Call increase/decrease method on the product object – Redisplay stock level

ProductInventoryApp

Class methods In some situations, a method related to a class need not be called on a specific object, such as when: – The method applies to all objects of a class – The class is viewed as a container or manager of its objects and the method is at the level of the manager Example: alloc is a “built-in” method of any class – [ alloc] returns a newly created/allocated instance/object under that class

NSString The method integerValue is an instance method of NSString that returns an int NSString *s int val = [s integerValue]; The method stringWithFormat is a class method of NSString that returns an NSString* NSString *x; x = [NSString stringWithFormat:"%d", val];

UIImage imageNamed is a class method of UIImage that returns a UIImage object given an image file name self.imageView.image = [UIImage In contrast, size is an instance method (actually, a property) that returns the size of a given image [self.imageView.image size]

Declaring and using class methods Use a + instead of a - when declaring and defining a class method: +(void) setInterestRate:(double)rate; You may not use properties in these methods – Properties represent instance-level data Example: an interestRate variable for a BankAccount class can be set by a class-level setInterestRate method – Declare interestRate in the.m file, outside of the methods

@interface (readwrite) BankAccount -(void) deposit:(double)amt { self.balance += amt; } double interestRate = 0.05; -(void) applyInterest { double amt = self.balance*interestRate; self.balance += amt; } +(void) setInterestRate:(double) rate { interestRate = rate; Declared outside the methods

Arrays Array: collection of variables of the same type Suppose you had three variables (type double) that represent the yearly incomes of three different employees: double income1; double income2; double income3; Use an array instead to declare them “in batch” double income[3];

Using arrays Assignment using the non-array version: income1 = ; income2 = ; income3 = ; Assignment using the array version income[0] = ; income[1] = ; income[2] = ; Syntax: [ ] If n is the size of the array, indices go from 0..n-1

Looping through array elements You may use loops to apply a statement for every array element Non-array version income1 = income1 + income1*0.10; income2 = income2 + income2*0.10; income3 = income3 + income3*0.10; Array version using a loop for(int i = 0; i <3; i++) income[i] = income[i] + income[i]*0.10;

Array of objects To store an array of five strings: NSString *words[5]; words[0] words[1] words[2] words[3] words[4] To print these strings: for( int i = 0; i < 5; i++ ) words[i]);

Array classes Arrays just discussed are “C-style” arrays Alternative: create array objects using the Objective-C classes NSArray or NSMutableArray NSArray (fixed-size) – Create and initialize using arrayWithObjects class method NSMutableArray (dynamically-sized) – Create using [[NSMutableArray alloc] init] – Add new elements using addObject method

Array classes To access individual elements – Use objectAtIndex method – Or use [ ] Use the count property to determine the current size of the array Refer to the test code in the course website for a demonstration of using NS array classes

Summary Class method – Method that isnot called on an instance (it may return an instance) – Method that manages objects of the class – Methods that sets or gets data at the level of the class Array – Collection of variables of the same type – Involves indexing and loops – C-style, NSArray, NSMutableArray