week 2 presentation introduction to ubiquitous computing ... · (cpl) week 2 presentation september...
TRANSCRIPT
![Page 1: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/1.jpg)
Week 2 PresentationIntroduction to Ubiquitous Computing
COSC 4355/6355Fall 2015
Ioannis PavlidisAshik Khatri
Dinesh Majeti
Computational Physiology Lab
[email protected]@[email protected]
September 10, 2015
(CPL) Week 2 Presentation September 10, 2015 1 / 21
![Page 2: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/2.jpg)
Evaluation
(CPL) Week 2 Presentation September 10, 2015 2 / 21
![Page 3: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/3.jpg)
Evaluation
(CPL) Week 2 Presentation September 10, 2015 3 / 21
![Page 4: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/4.jpg)
Objectives
Learn about Categories and Protocols
Understand Delegates and Data Sources
Implement Table View.
(CPL) Week 2 Presentation September 10, 2015 4 / 21
![Page 5: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/5.jpg)
Overview
1 Categories
2 Protocols
3 Delegates and Data Sources
4 The Structure of an App
5 References
(CPL) Week 2 Presentation September 10, 2015 5 / 21
![Page 6: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/6.jpg)
Categories
Categories help you to define additional methods of an existing class -even one whose source code is unavailable to you - withoutsubclassing.
The added methods are inherited by subclasses and areindistinguishable at runtime from the original methods of the class.
Categories also help to modularize a class.
(CPL) Week 2 Presentation September 10, 2015 6 / 21
![Page 7: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/7.jpg)
Categories Example
Category named NSString+Utilities.h.
#import <Foundation/Foundation.h>
@interface NSString (Utilities)
- (BOOL)containsOnlyLetters;
@end
Inside NSString+Utilities.m.
#import "NSString+Utilities.h"
@implementation NSString (Utilities)
- (BOOL)containsOnlyLetters
{
// implementation code goes here
}
@end
Can be called as [myString containsOnlyLetters]
(CPL) Week 2 Presentation September 10, 2015 7 / 21
![Page 8: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/8.jpg)
Protocols
A protocol defines a set of behaviors that are expected of an object ina given situation.
”Make sure this object has this particular set of functionality.”
A protocol comes in the form of a programmatic interface, one thatany class may implement.
(CPL) Week 2 Presentation September 10, 2015 8 / 21
![Page 9: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/9.jpg)
Types of Protocols
A formal protocol declares a list of methods that client classes areexpected to implement. Formal protocols are an extension to theObjective-C language.
An informal protocol is a category on NSObject, which implicitlymakes almost all objects adopters of the protocol.
As of Objective-C 2.0, protocols can have optional methods using the@optional keyword.
Until optional protocol methods were introduced in Objective-C 2.0,informal protocols were essential to the way classes implementeddelegation.
(CPL) Week 2 Presentation September 10, 2015 9 / 21
![Page 10: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/10.jpg)
Delegates and Data Sources
Delegates
A delegate is an object that acts on behalf of, or in coordination with,another object when that object encounters an event in a program.
The object that implements the delegate methods has theresponsibility to handle the user interface events.
Example - MKMapViewDelegate responds to events related to map.
Data Sources
A data source is like a delegate except that, instead of beingdelegated control of the user interface, it is delegated control of data.
A data source is an outlet held by UIView objects such as table viewsthat require a source from which to populate their rows of visible data.
(CPL) Week 2 Presentation September 10, 2015 10 / 21
![Page 11: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/11.jpg)
The App Delegate
The UIApplicationDelegate protocol defines methods that are calledby the singleton UIApplication object in response to important eventsin the lifetime of your app.
The app delegate works alongside the app object to ensure your appinteracts properly with the system and with other apps.
(CPL) Week 2 Presentation September 10, 2015 11 / 21
![Page 12: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/12.jpg)
Delegation Messages
Begin with the name of the UIKit object doing the delegating.
Example delegation methods -
// NSApplication
- (BOOL)application:(NSApplication *)sender
openFile:(NSString *)filename;
// UITableView
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath )indexPath
// UIApplication
- (void)applicationDidEnterBackground:
(UIApplication *)application
(CPL) Week 2 Presentation September 10, 2015 12 / 21
![Page 13: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/13.jpg)
The id type
The id type defines a generic object pointer. Enables polymorphism.
The compiler has no information about the actual type of id object.
id object1;
object1 = [[SavingsAccount alloc] init];
[object1 setAccount: 4543455 andBalance: 3010.10];
object1 = [[CustomerInfo alloc] init];
[object1 displayInfo];
(CPL) Week 2 Presentation September 10, 2015 13 / 21
![Page 14: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/14.jpg)
Applications of the id type
The id type is designed to be for any object type, but you can use thecompiler to ensure that only objects that conform to a protocol areassigned to the object.
id <NSCopying> delegate;
Remember that this is a compiler check, so it only works withstatically typed variables and objects.
(CPL) Week 2 Presentation September 10, 2015 14 / 21
![Page 15: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/15.jpg)
Introspection
Introspection refers to the capability of objects to divulge detailsabout themselves as objects at runtime.
Such details include an object’s place in the inheritance tree, whetherit conforms to a specific protocol, and whether it responds to acertain message.
Used judiciously, introspection makes an object-oriented programmore efficient and robust.
Two of the more powerful introspection methods of NSObject arerespondsToSelector: and conformsToProtocol:.
(CPL) Week 2 Presentation September 10, 2015 15 / 21
![Page 16: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/16.jpg)
The Main Function
Hands control off to the UIKit framework.
The UIApplicationMain function handles this process by creating thecore objects of your app, loading your app’s user interface from theavailable storyboard files, calling your custom code so that you have achance to do some initial setup, and putting the app’s run loop inmotion.
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil,
NSStringFromClass([AppDelegate class]));
}
}
(CPL) Week 2 Presentation September 10, 2015 16 / 21
![Page 17: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/17.jpg)
The Structure of an App
(CPL) Week 2 Presentation September 10, 2015 17 / 21
![Page 18: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/18.jpg)
The Main Run Loop
(CPL) Week 2 Presentation September 10, 2015 18 / 21
![Page 19: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/19.jpg)
References
Categories 1
Categories 2
Protocols
Protocols vs Categories
Introspection
Working with Objects
App delegate
The App Life Cycle
MVC
(CPL) Week 2 Presentation September 10, 2015 19 / 21
![Page 20: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/20.jpg)
Sending Messages to nil
In Objective-C, it is valid to send a message to nil - it simply has noeffect at runtime.
If the method returns an object, then a message sent to nil returns 0(nil), for example:
Person *motherInLaw = [[aPerson spouse] mother];
If aPerson’s spouse is nil, then mother is sent to nil and themethod returns nil.
(CPL) Week 2 Presentation September 10, 2015 20 / 21
![Page 21: Week 2 Presentation Introduction to Ubiquitous Computing ... · (CPL) Week 2 Presentation September 10, 2015 4 / 21. Overview 1 Categories 2 Protocols 3 Delegates and Data Sources](https://reader033.vdocuments.us/reader033/viewer/2022053003/5f075b3a7e708231d41c940a/html5/thumbnails/21.jpg)
NULL, nil, Nil, NSNull
NULL - (void *)0 - literal null value for C pointers
nil - (id)0 - literal null value for Objective-C objects
Nil - (Class)0 - literal null value for Objective-C classes
NSNull - [NSNull null] - singleton object used to represent null
NSNull: Something for Nothing!
(CPL) Week 2 Presentation September 10, 2015 21 / 21