About MSDOSX. Lecture 0

Similar documents
Object-Oriented Programming with Objective-C. Lecture 2

ITP 342 Mobile App Dev. Fundamentals

CS193E Lecture #3 Categories and Protocols Cocoa Memory Management

Mobile Application Development

CS193p Spring 2010 Thursday, April 29, 2010

Principles of Programming Languages. Objective-C. Joris Kluivers

ITP 342 Mobile App Dev. Fundamentals

IPHONE. Development Jump Start. phil nash levelofindirection.com

Review. iphone Application Programming Lecture 2: Objective-C, Cocoa. History. Objective-C. Device restrictions. Interaction paradigm changes

Cocoa. Last Week... Music 3SI: Introduction to Audio/Multimedia App. Programming. Today... Why Cocoa? Wikipedia - Cocoa

Review. iphone Application Programming Lecture 2: Objective-C, Cocoa. History. Objective-C. Device restrictions. Interaction paradigm changes

CS193P - Lecture 3. iphone Application Development. Custom Classes Object Lifecycle Autorelease Properties

IPHONE DEVELOPMENT. Getting Started with the iphone SDK

Design Phase. Create a class Person. Determine the superclass. NSObject (in this case)

Announcement. Final Project Proposal Presentations and Updates

My First Cocoa Program

OVERVIEW. Why learn ios programming? Share first-hand experience. Identify platform differences. Identify similarities with.net

Topics in Mobile Computing

Objective-C. Stanford CS193p Fall 2013

Working Effectively with Objective-C on iphone OS. Blaine Garst Wizard of Runtimes

Fall 2017 CISC124 9/16/2017

Stanford CS193p. Developing Applications for ios Fall Stanford CS193p. Fall 2013

CS 47. Beginning iphone Application Development

Objective-C Part 2 (ECS189H) Ken Joy Serban Porumbescu

Realm Mobile Database. Knoxville CocoaHeads April 2017 by Gavin Wiggins

ITP 342 Mobile App Development. Data Persistence

Objective-C: An Introduction (pt 1) Tennessee Valley Apple Developers Saturday CodeJam July 24, 2010 August 7, 2010

CS193P - Lecture 2. iphone Application Development. Objective-C Foundation Framework

ios: Objective-C Primer

ITP 342 Advanced Mobile App Dev. Memory

Objective-C ICT/7421ICTNathan. René Hexel. School of Information and Communication Technology Griffith University.

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?

ITP 342 Mobile App Development. Data Persistence

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Introduction to PyObjC

CS193E Lecture 7. Document-based Applications NSTableView Key-Value Coding

COMP327 Mobile Computing Session: Tutorial Objective-C and the Foundation Framework

CLOCK4 TUTORIAL VERY SIMPLE HELLO WORLD COCOA APPLICATION

Extensibility in GNUstep & Étoilé

ios Development Lecture 1 Introduction to Objective-C Ing. Simone Cirani

CLOCK TUTORIAL VERY SIMPLE HELLO WORLD COCOA APPLICATION

Forth Meets Smalltalk. A Presentation to SVFIG October 23, 2010 by Douglas B. Hoffman

Files & Archiving. Lecture 8

Objective-C and Cocoa User Guide and Reference Manual

Introductory ios Development

Introductory ios Development

CS193E: Temperature Converter Walkthrough

JAVA MOCK TEST JAVA MOCK TEST II

Contents. iphone Training. Industry Trainers. Classroom Training Online Training ON-DEMAND Training. Read what you need

An Introduction to Processing

Structs. Comp Sci 1570 Introduction to C++ Introduction. Aggregate data. Example. General syntax Object initialization Initialization and access

Mobile App Development. ios Platform

Objective-C and COCOA Applications

Cocoa Programming. David Chisnall. March 18,

2d video game development with MacRuby

Object Declaration. <class name>: the name of the class to which the object belongs <object name>: the name of the object (any valid identifier)

Principles of Object Oriented Programming. Lecture 4

Variables and Functions. ROBOTC Software

Mobile Application Development

NSObject. - (NSString *)description Provides us with a string description of the object

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

Author Bob Ippolito Conference. PyObjC Hacking. PyCon DC, March 2005

Review (Basic Objective-C)

Acollada ios Charting Components

C++ basics Getting started with, and Data Types.

Final exam. Final exam will be 12 problems, drop any 2. Cumulative up to and including week 14 (emphasis on weeks 9-14: classes & pointers)

Jython. An introduction by Thinh Le

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

Mobile Development - Lab 2

Media Playback and Recording. CS193W - Spring Lecture 3

An Introduction to Smalltalk for Objective-C Programmers

Programming Language Concepts, cs2104 Lecture 04 ( )

Computers, Variables and Types. Engineering 1D04, Teaching Session 2

JavaScript for Automation

Datatypes, Variables, and Operations

VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals

G Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University

Stanford CS193p. Developing Applications for iphone 4, ipod Touch, & ipad Spring Stanford CS193p Spring 2011

Introduction to Swift. Dr. Sarah Abraham

6.092: Java for 6.170

C# MOCK TEST C# MOCK TEST I

Fundamentals of Programming Session 23

Lecture 1. Types, Expressions, & Variables

MacOS X Cocoa Programming for Vision Scientist --- #1

Published by O'Reilly & Associates, Inc., 1005 Gravenstein Highway North, Sebastopol, CA

Lab # 02. Basic Elements of C++ _ Part1

Collections & Memory Management. Lecture 2

Constants are named in ALL_CAPS, using upper case letters and underscores in their names.

Objective-C Runtime. Cocoa s Jewel in the Crown. NSConference Nicolas

Cunning Plan. One-Slide Summary. Functional Programming. Functional Programming. Introduction to COOL #1. Classroom Object-Oriented Language

Advanced Object- C Features

Introductory ios Development

User Interfaces. Lecture 15. Application Programming on Mac OS. Hamza Bennani September 4, 2018

A A B U n i v e r s i t y

The MVC Design Pattern

Advanced Cocoa Text Tips and Tricks. Aki Inoue Cocoa Engineer

ENGR 102 Engineering Lab I - Computation

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Object-Oriented Programming in Objective-C

TYPES, VALUES AND DECLARATIONS

Transcription:

About MSDOSX Lecture 0

Goal: make an app of your own design for the Mac or iphone

The Plan Lectures + Labs for several weeks Project proposals (about halfway through the semester) Work on project Present project

Resources Stanford iphone class msdosx.berkeley.edu Apple documentation Email us!

Object-Oriented Programming with Objective-C Lecture 1

Objective-C

A Little History

A Little History 1980s Brad Cox & Tom Love

A Little History 1980s 1988 Brad Cox & Tom Love

A Little History 1980s 1988 1996 Brad Cox & Tom Love apple

Features Simple extension to C Low level efficiency and interoperability Dynamic runtime, like Smalltalk Optional static typing

Object-Oriented

I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages Alan Kay, one of the fathers of OOP

Procedural: functions operating on data Object-oriented: objects communicating with messages

Objects Method Internal State Method Method

Objects Method Internal State Method Method Method Method Internal State Method Reply Method

Objective-C Files Header file (public) Implementation file (private)

Header file #import <Cocoa/Cocoa.h> MyImage.h @interface MyImage : NSObject { NSString *name; char pixels[16][16]; } - (id)initwithname:(nsstring *)name; - (void)setname:(nsstring *)name; - (NSString *)name; - (char)getpixelatx:(int)x y:(int)y; - (void)setpixel:(char)value atx:(int)x y:(int)y; - (NSData *)imagedata; @end

MyImage.h Header file #import <Cocoa/Cocoa.h> @interface MyImage : NSObject { NSString *name; char pixels[16][16]; } Import Cocoa libraries so we can use Cocoa classes - (id)initwithname:(nsstring *)name; - (void)setname:(nsstring *)name; - (NSString *)name; - (char)getpixelatx:(int)x y:(int)y; - (void)setpixel:(char)value atx:(int)x y:(int)y; - (NSData *)imagedata; @end

Header file MyImage.h #import <Cocoa/Cocoa.h> @interface MyImage : NSObject { NSString *name; char pixels[16][16]; } - (id)initwithname:(nsstring *)name; - (void)setname:(nsstring *)name; - (NSString *)name; Create a new class called MyImage, a subclass of NSObject - (char)getpixelatx:(int)x y:(int)y; - (void)setpixel:(char)value atx:(int)x y:(int)y; - (NSData *)imagedata; @end

Header file #import <Cocoa/Cocoa.h> MyImage.h @interface MyImage : NSObject { NSString *name; char pixels[16][16]; } - (id)initwithname:(nsstring *)name; Define the instance variables for the MyImage class - (void)setname:(nsstring *)name; - (NSString *)name; - (char)getpixelatx:(int)x y:(int)y; - (void)setpixel:(char)value atx:(int)x y:(int)y; - (NSData *)imagedata; @end

Header file #import <Cocoa/Cocoa.h> MyImage.h @interface MyImage : NSObject { NSString *name; char pixels[16][16]; } - (id)initwithname:(nsstring *)name; Declare the methods for the MyImage class - (void)setname:(nsstring *)name; - (NSString *)name; - (char)getpixelatx:(int)x y:(int)y; - (void)setpixel:(char)value atx:(int)x y:(int)y; - (NSData *)imagedata; @end

Declaring a Method - (char)getpixelatx:(int)x y:(int)y;

Declaring a Method - (char)getpixelatx:(int)x y:(int)y; The return type of the method in other words, the type of the expression [obj getpixelatx:x y:y]

Declaring a Method - (char)getpixelatx:(int)x y:(int)y; The name of the method, also called its selector Objective-C uses named parameters, a feature from Smalltalk which improves readability

Declaring a Method - (char)getpixelatx:(int)x y:(int)y; Parameter variables with their types

Implementation file #import "MyImage.h" MyImage.m @implementation MyImage - (NSString *)name { return name; } - (void)setpixel:(char)value atx:(int)x y:(int)y { if (x < 0 y < 0 x >= 16 y >= 16) { [NSException raise:@"invalidrangeexception" format:@"pixel location outside image range"]; } pixels[x][y] = value; } // all the other methods @end

Implementation file MyImage.m #import "MyImage.h" @implementation MyImage - (NSString *)name { return name; } Import the header file so we know what weʼre implementing - (void)setpixel:(char)value atx:(int)x y:(int)y { if (x < 0 y < 0 x >= 16 y >= 16) { [NSException raise:@"invalidrangeexception" format:@"pixel location outside image range"]; } pixels[x][y] = value; } // all the other methods @end

Implementation file #import "MyImage.h" MyImage.m @implementation MyImage - (NSString *)name { return name; } Tell Obj-C we are defining methods for MyImage - (void)setpixel:(char)value atx:(int)x y:(int)y { if (x < 0 y < 0 x >= 16 y >= 16) { [NSException raise:@"invalidrangeexception" format:@"pixel location outside image range"]; } pixels[x][y] = value; } // all the other methods @end

Implementation file #import "MyImage.h" MyImage.m @implementation MyImage - (NSString *)name { return name; } Define the methods using Objective-C code - (void)setpixel:(char)value atx:(int)x y:(int)y { if (x < 0 y < 0 x >= 16 y >= 16) { [NSException raise:@"invalidrangeexception" format:@"pixel location outside image range"]; } pixels[x][y] = value; } // all the other methods @end

Sending a Message [object method];

Sending a Message int age1 = [person age]; int age2 = [[person father] age];

Sending a Message [array addobject:obj]; [array insertobject:obj atindex:0];

Variables Variables are declared just like in C: int i = 0, j; float x = 1.0; NSString *str = @"asdf"; Objects are always pointers (NSString *) Instead of "C strings", Cocoa uses @"NSStrings", which can contain Unicode text

Objective-C Types Dynamically-typed: id fido; Statically-typed: MyDog *fido; Objective-C uses dynamic binding; method names are not resolved until run time

self and super self is a reference to the current object - (NSTimeInterval)age { return [[NSDate date] timeintervalsincedate:[self birthday]]; } super allows access to the superclassʼs methods - (NSTimeInterval)age { return [super age] + 60; }

Adventure!

Class Methods + (BOOL)isSubclassOfClass:(Class)aClass; The plus sign indicates that this is a class method, received by the class itself (instead of some particular instance of the class)

Class Methods + (BOOL)isSubclassOfClass:(Class)aClass; Class methods are called on the class itself [NSButton issubclassofclass:[nscontrol class]]

nil nil is the nothing object If person == nil then: [person age] == 0 [person name] == nil [person eat:taco] // fails silently Some methods take nil as a donʼt care parameter

BOOL ObjC C++ / C99 actual value C YES true 1 TRUE NO false 0 FALSE

Selectors Includes all colons SEL fetchselector = @selector(fetch:); [fido performselector:fetchselector withobject:theball]; is equivalent to [fido fetch:theball]; but you can store SELs and pass them around (you can even call NSSelectorFromString(NSString *aselectorname)!)

Selectors in Cocoa Delegates / duck typing if ([obj respondstoselector:@selector(fetch:)]) { [obj fetch:theball]; } Target / action pattern [button settarget:self]; [button setaction:@selector(buttonpressed:)];

Naming Conventions Variables start with a lowercase letter and use capitalization to distinguish words: e.g. thisisagoodname, but not a_bad_name Class names start with a prefix indicating the project, company, or author to avoid name collisions: e.g. SRScroller or ProjMainView, but not mutablestring or TEXT_FIELD