24
Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti Computational Physiology Lab [email protected] [email protected] [email protected] September 3, 2015 (CPL) Week 1 Presentation September 3, 2015 1 / 24

Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Week 1 PresentationIntroduction to Ubiquitous Computing

COSC 4355/6355Fall 2015

Ioannis PavlidisAshik Khatri

Dinesh Majeti

Computational Physiology Lab

[email protected]@[email protected]

September 3, 2015

(CPL) Week 1 Presentation September 3, 2015 1 / 24

Page 2: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Overview

1 Objective-CPropertiesFunctionsClassesObjectsCollections

2 XcodeIBOutletsIBAction

3 References

(CPL) Week 1 Presentation September 3, 2015 2 / 24

Page 3: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Evaluation

(CPL) Week 1 Presentation September 3, 2015 3 / 24

Page 4: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Evaluation

(CPL) Week 1 Presentation September 3, 2015 4 / 24

Page 5: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Objective-C

Objective-C separates the interface declaration and theimplementation of a class in .h and .m files.

All functionality that shall be available to other classes needs to beplaced in the .h file of a class, all implementations and all privatefunctionality is placed in the .m file.

(CPL) Week 1 Presentation September 3, 2015 5 / 24

Page 6: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Properties

The goal of the @property directive is to make it easy to create andconfigure properties by automatically generating accessor methods.

Property attributes indicate data accessibility and storageconsiderations.

(CPL) Week 1 Presentation September 3, 2015 6 / 24

Page 7: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Properties

readonly - Don’t synthesize a setter method.

nonatomic - Don’t guarantee the integrity of accessors in amulti-threaded environment. This is more efficient than the defaultatomic behavior.

strong - Create an owning relationship between the property and theassigned value. This is the default for object properties.

@property (nonatomic, strong) Car *car;

weak - Create a non-owning relationship between the property andthe assigned value. Use this to prevent retain cycles.

copy - Create a copy of the assigned value instead of referencing theexisting instance.

(CPL) Week 1 Presentation September 3, 2015 7 / 24

Page 8: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Functions

Example C function -

void setName(String name);

void setFirstNameAndLastName(String firstName,

String lastName);

Functions in Objective-C

- (void)setName:(NSString*)name;

- (void)setFirstName:(NSString*)firstName

andLastName:(NSString*)lastName;

(CPL) Week 1 Presentation September 3, 2015 8 / 24

Page 9: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Classes

The Objective-C syntax used to declare a class interface looks likethis:

@interface SimpleClass : NSObject

@end

This example declares a class named SimpleClass, which inheritsfrom NSObject.

Class methods are denoted by the use of a + sign, whichdifferentiates them from instance methods using a − sign.+ (id)stringWithString:(NSString *)aString;

(CPL) Week 1 Presentation September 3, 2015 9 / 24

Page 10: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Objects

Objects send and receive messages.

[someObject doSomething];

When the above line of code is executed, someObject will be sentthe doSomething message.

Objects can send messages to themselves.

@implementation XYZPerson

- (void)sayHello {

[self saySomething:@"Hello, world!"];

}

- (void)saySomething:(NSString *)greeting {

NSLog(@"%@", greeting);

}

@end

(CPL) Week 1 Presentation September 3, 2015 10 / 24

Page 11: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Objects

Objects are created dynamically.

The NSObject root class provides a class method, alloc, whichhandles this process for you

+ (id)alloc;

The alloc method has one other important task, which is to clearout the memory allocated for the object’s properties by setting themto zero. This avoids the usual problem of memory containing garbagefrom whatever was stored before, but is not enough to initialize anobject completely.

- (id)init;

NSObject *newObject = [[NSObject alloc] init];

(CPL) Week 1 Presentation September 3, 2015 11 / 24

Page 12: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

String Objects

Strings are represented by NSString class.

The basic NSString class is immutable.

NSString *name = @"John";

name = [name stringByAppendingString:@"ny"];

// returns a new string object

The NSMutableString class is the mutable subclass of NSString,and allows you to change its character contents at runtime usingmethods like appendString: or appendFormat:, like this:

NSMutableString *name = [NSMutableString

stringWithString:@"John"];

[name appendString:@"ny"]; // same object,

but now represents "Johnny"

(CPL) Week 1 Presentation September 3, 2015 12 / 24

Page 13: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Collections

Most collections in Objective-C code are instances of one of theCocoa and Cocoa Touch collection classes, like NSArray, NSSet

and NSDictionary.

These classes are used to manage groups of objects and areimmutable.

(CPL) Week 1 Presentation September 3, 2015 13 / 24

Page 14: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Array

An NSArray is used to represent an ordered collection of objects. Theonly requirement is that each item is an Objective-C object - there’sno requirement for each object to be an instance of the same class.

NSArray *someArray =

[NSArray arrayWithObjects:someObject,

someString, someNumber, someValue, nil];

NSArray *someArray = @[firstObject, secondObject,

thirdObject];

(CPL) Week 1 Presentation September 3, 2015 14 / 24

Page 15: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Dictionary

NSDictionary stores objects against given keys, which can then beused for retrieval.

NSDictionary *dictionary =

[NSDictionary dictionaryWithObjectsAndKeys:

someObject, @"anObject",

@"Hello, World!", @"helloString",

@42, @"magicNumber",

someValue, @"aValue",

nil];

Each object is specified before its key, and the list of objects and keysmust be nil-terminated.

(CPL) Week 1 Presentation September 3, 2015 15 / 24

Page 16: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

”No object”

It’s not possible to add nil to the collection classes described in thissection because nil in Objective-C means ”no object.”

If you need to represent ”no object” in a collection, you can use theNSNull class:

NSArray *array = @[ @"string", @42, [NSNull null] ];

NSNull is a singleton class, which means that the null method willalways return the same instance.

(CPL) Week 1 Presentation September 3, 2015 16 / 24

Page 17: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Xcode

Figure 1: Xcode interface

(CPL) Week 1 Presentation September 3, 2015 17 / 24

Page 18: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Xcode

Figure 2: Xcode toolbar

(CPL) Week 1 Presentation September 3, 2015 18 / 24

Page 19: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Xcode

Figure 3: Xcode utilities area

(CPL) Week 1 Presentation September 3, 2015 19 / 24

Page 20: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Outlets

An outlet is a property of an object that references another object.

The containing object holds an outlet declared as a property with thetype qualifier of IBOutlet and a weak option.

An outlet is declared as a weak reference to prevent strong referencecycles.@property (weak) IBOutlet NSArray *keywords;

(CPL) Week 1 Presentation September 3, 2015 20 / 24

Page 21: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Actions

Whenever the user activates a control, such as by tapping it, thecontrol should send a message instructing your code to perform someaction. You can do this by creating an IBAction.

(CPL) Week 1 Presentation September 3, 2015 21 / 24

Page 22: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

Actions

(CPL) Week 1 Presentation September 3, 2015 22 / 24

Page 24: Week 1 Presentation Introduction to Ubiquitous Computing ...Week 1 Presentation Introduction to Ubiquitous Computing COSC 4355/6355 Fall 2015 Ioannis Pavlidis Ashik Khatri Dinesh Majeti

On the lighter side...

I once told an Objective-C joke, but nobody got the message! :)

(CPL) Week 1 Presentation September 3, 2015 24 / 24