1 / 64

Wednesday 2-4, DH 1046

Wednesday 2-4, DH 1046. COMP 446 / ELEC 446 Mobile Device Applications. Scott Cutler Professor in the Practice of Computer Technology Department of Computer Science Department of Electrical and Computer Engineering cutler@rice.edu 9/7/11. Today’s Agenda. Events of the week

linus-levy
Télécharger la présentation

Wednesday 2-4, DH 1046

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Wednesday 2-4, DH 1046 COMP 446 / ELEC 446 Mobile Device Applications Scott Cutler Professor in the Practice of Computer Technology Department of Computer Science Department of Electrical and Computer Engineering cutler@rice.edu 9/7/11

  2. Today’s Agenda • Events of the week • Final Project Philosophy • Review of current assignment • Cocoa Touch and Objective C • Next Week • Views, drawing, application life cycle • Assignment 3, Videos 5 and 6 • Graphing version of this week’s calculator COMP 446 / ELEC 446 - Week 3

  3. Events of the Week • Apple loses another unreleased iPhone • Google+ weekly visits on the decline • Windows 8 to offer both Metro and desktop interface • Judge rejects Oracle's $1.3 billion award against SAP • Toshiba's new AT200 is thinner than iPad, Galaxy Tab • Samsung Shows Galaxy Tab 7.7, Galaxy Note Android Phone • Dell to team with search engine Baidu on tablets, phones • Report details $250 Amazon Kindle tablet due in November COMP 446 / ELEC 446 - Week 3

  4. Current Roster • Waseem Ahmad • Joe Abdou • Carrie Boland • George Chen • Emmanuel Fuentes • Ivan Hernandez • Myuran Kanga • Sunny Kim COMP 446 / ELEC 446 - Week 3

  5. Current Roster (2) • Lan Li • Manan Mehta • Dennis Qian • Caleb Solano • Daphne Wert • Wen Xing • Fred Liu • Richard Latimer COMP 446 / ELEC 446 - Week 3

  6. Assignment Files • Unless otherwise instructed, submit assignment files as a zip file of Xcode project directory. • Ensure that all resources are part of the project directory so they are included in zip. • Clean project before archiving. Greatly reduces size. • Screen shots or PDF documents preferred for some assignments (when indicated). • OK to make multiple submissions when both file types needed – but not of individual Xcode project files. COMP 446 / ELEC 446 - Week 3

  7. COMP 446 (tentative) Syllabus • 8/24/11 Introduction / What makes mobile apps special Videos: Lecture 1. Introduction to Cocoa Touch, Objective-C, Tools, and MVC (September 21, 2010) Lecture 2. Building a Simple Calculator (September 23, 2010) Assignment: #1 and #1 Walkthrough - Calculator Due: Preferably watch videos this week, definitely by 8/30. Assignment due 9/1/11. • 8/31/11 Discussion of first applications, Development Environment Videos: Lecture 3. Objective-C and Foundation Frameworks (September 28, 2010) Lecture 4. Foundation and Memory Management (September 30, 2010) Assignment: #2 Function Calculator (Due 9/08/11) • 9/7/11 Intro to Cocoa Touch, Objective-C, Using Objective-C, Foundation framework Videos: Lecture 5. Protocols and Views (October 5, 2010) Lecture 6. Application & View Controller Lifecycle, Navigation Controller (October 7, 2010) Assignment: #3 Graphing Calculator (Due 9/15/11) • 9/14/11 ASP.Net with a little HTML Videos: Lecture 7. More Controllers of Controllers, iPad, Universal Applications (October 12, 2010) Lecture 8. Gesture Recognizers (October 14, 2010) Assignment: #4 Universal Calculator (Due 9/22/11) • 9/21/11 iPhone (pseudo) Web Apps / Browser Capabilities Videos: Lecture 9. Image View, Web View, and Scroll View (October 19, 2010) Lecture 10. Table View (October 21, 2010) Assignment: #5 Pictures Places (Due 10/06/11) COMP 446 / ELEC 446 - Week 3

  8. COMP 446 (tentative) Syllabus • 9/28/11 SQL 101 Videos: Debugging Tools (October 22, 2010)Kleiner Perkins iFund (October 15, 2010) Assignment: None. Review previous material • 10/5/11 Creating and Consuming Web Services Videos: Lecture 11. Persistence (October 26, 2010) Lecture 12. Core Data and Table Views (October 28, 2010) Assignment: #6 Core Data Places (Due 10/20/11, but watch lectures prior to 10/12/11 class) • 10/12/11 Final Project discussion and Pairing Videos: Lecture 13. Blocks and Multithreading (November 2, 2010) Lecture 14. Core Location and Map Kit (November 9, 2010) Assignment: Final Project Proposal (Due 10/18/11 along with Core Data Places due 10/20/11) • 10/19/11 iOS 5 Videos: Lecture 15. Editable Text, Modal View Controllers, and View Animation (Nov 11, 2010) Lecture 16. Core Motion, Segmented Control, and Alerts (November 16, 2010) Assignment: Final Project, Stage 1 (Due 10/27/11) • 10/26/11 Android Videos: Lecture 17. Media (November 18, 2010) Lecture 18. Accessibility on iOS: Make an App for Everyone (November 30, 2010) Assignment: Advanced Feature App (Due 11/03/11) COMP 446 / ELEC 446 - Week 3

  9. COMP 446 (tentative) Syllabus • 11/2/11 Windows Phone 7, Final Project Prep Videos: Assignment: Final Project, Stage 2 (Due 11/10/2011) • 11/09/11 Final Project Prep / iPhone v. Android v. Windows Phone 7 group discussion Videos: Lessons from Bezos, Pincus, Young: CEO 2.0 (November 12, 2010) (Optional) LinkedIn: Shipping with CoreData (November 5, 2010) (Optional) Assignment: Final Project, Stage 3 (Due 11/17/2011) • 11/16/11 Final Project Prep Videos: Building Flipboard (November 19, 2010) (Optional) Assignment: Final Project Presentation (Due 11/30/2011) • 11/23/11 Thanksgiving – Continue Final Projects on your own • 11/30/11 Demonstrate Final Projects to class • 12/4/11 Class Offsite – Sunday (tentative) • Finals Submission of final code due by official finals date COMP 446 / ELEC 446 - Week 3

  10. Final Project • To be determined by end of 6th week • Can target iOS, Android or WP7 device • Topic chosen class before mid semester break • Proposal submitted by 10/18/11 • Full Spec 10/27/11 • Various milestones including presentation to class on 12/30/11 • Final code for project incorporating comments from presentation due on the official finals date of the course. • This is VERY important: If you do not have a great project definition, the 2nd half of the course will suffer. With a great project, this will be an exciting course. • Projects can be done solo and in pairs. Richard Latimer can not be part of project team. • Great if your project could have life after the class finishes COMP 446 / ELEC 446 - Week 3

  11. Assignment #2 Questions COMP 446 / ELEC 446 - Week 3

  12. Week 4 • Watch CS193p lectures #5 and #6 • Preferably before Saturday. Definitely before next class. • Complete CS193p Assignment #3 • Try and complete before next class. Due day after next class. • Submit assignments, review lectures at www.comp446.com • Start thinking about big project COMP 446 / ELEC 446 - Week 3

  13. COMP 446 / ELEC 446 Mobile Wireless Services Project Objective-C and Foundation Framework Scott Cutler Professor in the Practice of Computer Technology Department of Computer Science Department of Electrical and Computer Engineering cutler@rice.edu 9/07/11

  14. About this Slide Set • Most of the content derived directly from Stanford University’s CS193p, Winter 2010 class as published on iTunes University. • See the original material on iTunes or at: http://www.stanford.edu/class/cs193p/cgi-bin/drupal/downloads-2010-winter COMP 446 / ELEC 446 - Week 3

  15. Learning Objective C • This is an important lecture. Go over it as many times as required for understanding. • If you are unsure, pull down and watch lecture 2 from the Spring 2009 Alan Cannistraro iTunes lecture. • Don’t be intimidated. • Soon you will know when to use: • ; + - { } [ ] ( ) * ** : @ // . # ! += % == • You will learn that: • LastName is not the same as lastName • Simple things are often complex • Complex things are often simple • Apple makes it easy for your app to look & feel like an iPhone app COMP 446 / ELEC 446 - Week 3

  16. OOP Vocabulary • Class: defines the grouping of data and code, the “type” of an object • Instance: a specific allocation of a class • Method: a “function” that an object knows how to perform • Instance Variable (or “ivar”): a specific piece of data belonging to an object • Encapsulation: keep implementation private and separate from interface • Inheritance: hierarchical organization, share code, customize or extend behaviors COMP 446 / ELEC 446 - Week 3

  17. Inheritance • Hierarchical relation between classes • Subclass “inherit” behavior and data from superclass • Subclasses can use, augment or replace superclass methods NSObject Memory management Superclass UIControl Generic Behaviors Subclass UIButton UITextField Specific Behaviors COMP 446 / ELEC 446 - Week 3

  18. Objective-C COMP 446 / ELEC 446 - Week 3

  19. Objective-C • Strict superset of C • Mix C with ObjC • Or even C++ with ObjC (usually referred to as ObjC++) • A very simple language, but some new syntax • Single inheritance, classes inherit from one and only one superclass • Protocols define behavior that cross classes (delegates) • Dynamic runtime • Loosely typed, if you’d like COMP 446 / ELEC 446 - Week 3

  20. Syntax Additions • Small number of additions • Some new types • Anonymous object • Class • Selectors • Syntax for defining classes • Syntax for message expressions COMP 446 / ELEC 446 - Week 3

  21. Dynamic Runtime • Object creation • All objects allocated out of the heap • No stack based objects • Message dispatch • Introspection COMP 446 / ELEC 446 - Week 3

  22. OOP with ObjC COMP 446 / ELEC 446 - Week 3

  23. Classes and Instances • In Objective-C, classes and instances are both objects • Class is the blueprint to create instances COMP 446 / ELEC 446 - Week 3

  24. Classes and Objects • Classes declare state and behavior • State (data) is maintained using instance variables • Behavior is implemented using methods • Instance variables typically hidden • Accessible only using getter/setter methods COMP 446 / ELEC 446 - Week 3

  25. Messaging syntax COMP 446 / ELEC 446 - Week 3

  26. Class and Instance Methods • Instances respond to instance methods • - (id)init; • - (float)height; • - (void)walk; • Classes respond to class methods • + (id)alloc; • + (Person *)sharedPerson; COMP 446 / ELEC 446 - Week 3

  27. Message syntax • [receiver message] • [receiver message:argument] • [receiver message:arg1 andArg:arg2] COMP 446 / ELEC 446 - Week 3

  28. Message examples Person *voter; //assume this exists likely through Person *voter = [[Person alloc] init]; [voter castBallot]; inttheAge = [voter age]; or inttheAge= voter.age; [voter setAge:21]; or voter.age=21; if ([voter canLegallyVote]) { // do something voter-y } [voter registerForState:@"CA" party:@"Independent"]; NSString *spouseName = [[voter spouse] name]; COMP 446 / ELEC 446 - Week 3

  29. Method definition examples Person *voter; //assume this exists - (void)castBallot; [voter castBallot]; - (int)age; inttheAge = [voter age]; - (void)setAge:(int)age; [voter setAge:21]; - (BOOL)canLegallyVote; if ([voter canLegallyVote]) { // do something voter-y } - (void)registerForState:(NSString*)state party:(NSString*)party; [voter registerForState:@"CA" party:@"Independent"]; - (Person *)spouse; - (NSString *)spouseName; NSString *spouseName= [[voter spouse] name]; COMP 446 / ELEC 446 - Week 3

  30. Terminology • Message expression [receiver method: argument] • Message [receiver method: argument] • Selector [receiver method: argument] • Method The code selected by a message COMP 446 / ELEC 446 - Week 3

  31. Dot Syntax • Objective-C 2.0 introduced dot syntax • Convenient shorthand for invoking accessormethods 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; COMP 446 / ELEC 446 - Week 3

  32. Objective-C Types COMP 446 / ELEC 446 - Week 3

  33. Dynamic and static typing • Dynamically-typed object id anObject • Just id • Not id * (unless you really, really mean it...) • Statically-typed object Person *anObject • Objective-C provides compile-time, not runtime, type checking • Objective-C always uses dynamic binding COMP 446 / ELEC 446 - Week 3

  34. The nil 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? person = nil; [person castBallot]; COMP 446 / ELEC 446 - Week 3

  35. BOOL typedef • When ObjC was developed, C had no boolean type (C99 introduced one) • ObjCuses a typedef to define BOOL as a type BOOL flag = NO; • Macros included for initialization and comparison: YES and NO if (flag == YES) if (flag) if (!flag) if (flag != YES) flag = YES; flag = 1; COMP 446 / ELEC 446 - Week 3

  36. Selectors identify methods by name • A selector has type SEL SEL action = [button action]; [button setAction:@selector(start:)]; • Conceptually similar to function pointer • Selectors include the name and all colons, for example: -(void)setName:(NSString *)name age:(int)age; would have a selector: SEL sel = @selector(setName:age:); COMP 446 / ELEC 446 - Week 3

  37. Working with selectors • You can determine if an object responds to a given selector id obj; SEL sel = @selector(start:); if ([objrespondsToSelector:sel]) { [objperformSelector:selwithObject:self] } • This sort of introspection and dynamic messaging underlies many Cocoa design patterns -(void)setTarget:(id)target; -(void)setAction:(SEL)action; COMP 446 / ELEC 446 - Week 3

  38. Working with Classes COMP 446 / ELEC 446 - Week 3

  39. Class Introspection • You can ask an object about its class Class myClass = [myObject class]; NSLog(@"My class is %@", [myObjectclassName]); • Testing for general class membership (subclasses included): if ([myObjectisKindOfClass:[UIControl class]]) { // something } • Testing for specific class membership (subclasses excluded): if ([myObjectisMemberOfClass:[NSString class]]) { // something string specific } COMP 446 / ELEC 446 - Week 3

  40. Working with Objects COMP 446 / ELEC 446 - Week 3

  41. Identity versus Equality • Identity—testing equality of the pointer values if (object1 == object2) { NSLog(@"Same exact object instance"); } • Equality—testing object attributes if ([object1 isEqual: object2]) { NSLog(@"Logically equivalent, but may be different object instances"); } COMP 446 / ELEC 446 - Week 3

  42. -description • NSObject implements -description - (NSString *)description; • Objects represented in format strings using %@ • When an object appears in a format string, it is asked for its description [NSStringstringWithFormat: @”The answer is: %@”, myObject]; • You can log an object’s description with: NSLog([anObject description]); • Your custom subclasses can override description to return more specific information COMP 446 / ELEC 446 - Week 3

  43. Foundation Classes COMP 446 / ELEC 446 - Week 3

  44. Foundation Framework • Value and collection classes • User defaults • Archiving • Notifications • Undo manager • Tasks, timers, threads • File system, pipes, I/O, bundles COMP 446 / ELEC 446 - Week 3

  45. NSObject • Root class • Implements many basics • Memory management • Introspection • Object equality COMP 446 / ELEC 446 - Week 3

  46. NSString • General-purpose Unicode string support • Unicode is a coding system which represents all of the world’s languages • Consistently used throughout Cocoa Touch instead of “char *” • Without doubt the most commonly used class • Easy to support any language in the world with Cocoa COMP 446 / ELEC 446 - Week 3

  47. String Constants • In C constant strings are “simple” • In ObjC, constant strings are @“just as simple” • Constant strings are NSString instances NSString*aString = @”Hello World!”; COMP 446 / ELEC 446 - Week 3

  48. Format Strings • Similar to printf, but with %@ added for objects NSString *aString = @”Johnny”; NSString*log =[NSStringstringWithFormat: @”It’s ‘%@’”, aString]; log would be set to It’s ‘Johnny’ • Also used for logging NSLog(@”I am a %@, I have %d items”, [array className], [array count]); would log something like: I am a NSArray, I have 5 items COMP 446 / ELEC 446 - Week 3

  49. NSString • Often ask an existing string for a new string with modifications - (NSString *)stringByAppendingString:(NSString *)string; - (NSString *)stringByAppendingFormat:(NSString *)string; - (NSString *)stringByDeletingPathComponent; • Example: NSString *myString = @”Hello”; NSString *fullString; fullString= [myStringstringByAppendingString:@” world!”]; fullString would be set to Hello world! COMP 446 / ELEC 446 - Week 3

  50. NSString • Common NSString methods - (BOOL)isEqualToString:(NSString *)string; - (BOOL)hasPrefix:(NSString *)string; - (int)intValue; - (double)doubleValue; • Example: NSString *myString = @”Hello”; NSString *otherString = @”449”; if ([myStringhasPrefix:@”He”]) { // will make it here } if ([otherStringintValue] > 500) { // won’t make it here } COMP 446 / ELEC 446 - Week 3

More Related