61
Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction Connection Inspector then wrote init, showQuestion, and showAnswer

Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

Embed Size (px)

Citation preview

Page 1: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

Last Lecture•objective C memory management rules

•Wrote our first iPhone app

•a quiz app

•xib and nib files and interface editor

•MVC pattern

•IBOutlet IBAction

•Connection Inspector

•then wrote init, showQuestion, and showAnswer

Page 2: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

Core Location Framework

•whereami application

•classes that enable finding geographical position

•distanceFilter and desiredAccuracy properties

Page 3: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 4: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

Delegation

•locationManager:didUpdateToLocation:fromLocation:

•sent to “delegate” which we want WhereamiAppDelegate to be

Page 5: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 6: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

Delegation•the design pattern...

•an OO approach to callbacks

•allows callback methods to share data

•a delegate can only be sent messages specified in its protocol

•for every object that can have a delegate, there is a corresponding protocol

Page 7: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

some funcs removed

Page 8: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•like “interfaces” in other langs... i.e. no impl

•protocols for delegations “delegate protocols”

•can be used to ask things from the delegate or inform of updates

•can be @optional methods... by default required... here all were optional

Page 9: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•every object implements respondsToSelector:

•something like this (above)

•class has to declare protocols it implements like other langs

•no warning anymore

Page 10: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

memory and delegation

•delegates are usually controllers

•delegates never retained

•retain cycle

•assign attrib... weak reference

Page 11: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

lets display a map of current location

Page 12: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

whereami object diagram

Page 13: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•Several instances of MKAnnotationView appear as icons on the MKMapView.

•An MKMapView displays the map and the labels for the recorded locations.

•A UIActivityIndicatorView indicates that the device is working and not stalled.

•A UITextField allows the user to input text to label the current location on the map.

Page 14: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•#import <MapKit/MapKit.h>

•drag the map view onto UIWindow

Page 15: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 16: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•all we do is set showsUserLocation property of MKmapview and it will show user’s location

Page 17: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•too big the dot on world map

•want to zoom in

•when to send a zoom in message

•instead MKMapView has delegate

Page 18: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

lets add an annotation

•MKAnnotation protocol

•lets create a new MapPoint class

Page 19: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 20: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 21: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•in xib file set text field’s delegate to be the instance of WhereamiAppDelegate.

•this means we can implement methods from UITextFieldDelegate

Page 22: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 23: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 24: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 25: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

Touch

•touch events are hallmark of mobile devices

•lets make a drawing app like brushes

Page 26: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

touch events

Page 27: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•events added to event queue

•A UITouch object created and tracked for a finger

•set of UITouches passed... one per finger

•only the moving, begining, or ending event passed

•lets make our app

Page 28: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 29: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•use IB to set the view to default

Page 30: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 31: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 32: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 33: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 34: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

Blocks in ios 4.0

•change colors based on angle and length

Page 35: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 36: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 37: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

blocks = anonymous

methods

Page 38: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 39: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

colors when you shake

Page 40: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•blocks capture variables like anonymous functions in c#

•inline block objects (values copied)

•blocks are an alternate to callbacks

•blocks are used for GCD... kind of like tasks

Page 41: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

grand central dispatch

•dispatch queues

•pools of threads managed by

Page 42: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

threads

Page 43: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•calling back on UI thread

Page 44: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 45: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

lets download an image

asynchronously

Page 46: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 47: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•generate 10k random numbers if needed

•read 10K random numbrs, sort n display

•UITableView

Page 48: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 49: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction
Page 50: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•dispatch_after dispatches after a delay

•timers

•dependencies

•group of tasks

Page 51: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•Where did we start from

•Where to go from here

Page 52: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•started with handling multiple input sources in C++, discovered message loop

•refactored, understood events, event processing, source, target, event object

•downloaded VS and c# language and its features

•examples of OO programming in c#

Page 53: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•delegates, events, exception handling, attributes, collections

•worked with XML docs

•wpf history and xaml

•property elements and markup extensions

•mixing xaml and procedural code

Page 54: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

• logical and visual trees

•dependency properties

•change notifications

•prop val. inheritance

•attached properties

•sizing, positioning, and transforming elements

Page 55: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•transforms

•panels stackpanel, wrappanel, canvas, dockpanel, grid

•content overflow, clipping, scaling, scrolling

•events, input events, attached events,

•touch events (manipulation... high level)

•commands, persisting and restoring

Page 56: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•resources... binary and logical

•static vs dynamic logical resources

•data binding, binding object, binding markup extension

•binding to collection, implicit datacontext

•datatemplates and value converters

•customizing collection view... sorting, filtering, grouping, navigating

•data providers... xml and object data providers

Page 57: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•concurrency and threads

•captured variables

•synchronization context and tasks

•continuations

•task completion source

•sync vs async

Page 58: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•course grained vs fine grained sync

•async wait keywords in c# 5.0

•parallelism

•cancellation and progress reporting

•task combinator and task parallel library

•Parallel.Invoke, For, ForEach

•concurrent collections

Page 59: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•JS history and jQuery library

•HTML CSS JS

•client side vs server side

•dom

•jQuery selectors and filters

•changing attributes and elements

•events and animations

•ajax... xmlhttprequest, get put load

•JSON...

Page 60: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•mobile development

•objective C history

•call syntax and OO concepts

•properties

•retain count and memory management

•xib, nib, iboutlet, ibaction, interface builder

Page 61: Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction

•button events and a QA app

•protocols and delegates

•location and map kits

•touch events and blocks

•GCD and multithreading