art40545 n.
Skip this Video
Loading SlideShow in 5 Seconds..
ART40545 PowerPoint Presentation
Download Presentation

Loading in 2 Seconds...

play fullscreen
1 / 32

ART40545 - PowerPoint PPT Presentation

  • Uploaded on

ART40545. Basics of Programming:IOS Kris Secor. Week 2. Who is Wayne Dobson ?. First Responder…. The most prominent UIElement interacting with a user at a given time Let’s remove that keyboard! Now let’s add a background button. Delegate. for in loop.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'ART40545' - maik

Download Now 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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript


Basics of Programming:IOS

Kris Secor

IOS Development

week 2
Week 2
  • Who is Wayne Dobson?

IOS Development

first responder
First Responder….
  • The most prominent UIElement interacting with a user at a given time
  • Let’s remove that keyboard!
  • Now let’s add a background button

IOS Development


IOS Development

for in loop
for in loop
  • Introduced in Objective-C 2.0 (“fast enumeration”)

for(Item_Type *item in Collection_of_Items) {

//do whatever with the item

Nslog(@” Looking now at %@”, item);


Note: %@ in the NSLogconverts whatever is passed

(in this case item) to a string

c style arrays
C-style arrays

int multipleValues[5];

multipleValues[0] = 50;

multipleValues[1] = 60;


int multipleValues[5] = {50,60,70,80,90}; or

int multipleValues[0] = {50,60,70,80,90};

IOS Development

c style arrays with objects
C-Style Arrays with Objects


NSString *stringArray[5];

stringArray[0] = [[NSStringalloc] initwithString:@”Hello”];

stringArray[0] release;

Informal (without memory);

NSString *stringArray[5] = {@”first”,@”second”,@”third”,@”fourth”,@”fifth”};

NSLog (@”The first member is %@”,stringArray[0]);

  • //no bounds checking
  • //can’t mix types
  • //fixed size

IOS Development

array objects and methods
Array Objects and Methods


NSMutableArray *array = [[NSMutableArrayalloc]init];

for (i=0;i<10;++i){

[array addObject:[NSStringstringWithFormat:@"%d", (i*3)]];



for (id obj in array){

NSLog(@"array element %i is %@",y,obj);

y++; }

IOS Development

functions pass by reference
Functions --- pass by reference

void myFunction(void) {

for ( inti = 1 ; i < 5000 ; i++ ) {

if (i % 5 == 0) {

continue; // jump back to the top.


NSLog(@"The value of the index is %i", i);



int main (intargc, const char * argv[])


NSAutoreleasePool * pool = [[NSAutoreleasePoolalloc] init];

// call the function


[pool drain];

return 0;


passing arguments
Passing Arguments

void myFunction(intx, inty) {

NSLog(@"The value of the x is %i and the value of y is %i",x,y);


int main (intargc, const char * argv[]){

// call the function


return 0;


IOS Development

pointers and objects
Pointers and Objects

NSMutableString *message = @"Hello"; NSString *newmessage = [message insertString:@" Kris, how are you?" atIndext:3];

NSLog(@"The new message is @%",newmessage);

IOS Development

passing the pointer
Passing the pointer

Void myFunction (NSString *inbound) {NSLog(@”The message was %@ “,inbound);


NSString *message = @”Hello”;


Let’s look at some basics and run it:

Code Break!

IOS Development

  • Have both definition file (interface) and implementation file : classname.h and classname.m
  • Similar to how have .h and .cpp in C++
declaring a class in classname h
Declaring a class in ClassName.h

#import <Cocoa/Cocoa.h>

@interface ClassName : Parent {

//class variables

int age;

NSString name;


// methods declared






#import <standardimports.h>

#import “local-your-otherfiles.h”

@interface ClassName: Parent {

//class variables



-(return_type) methodName:(type)param1, (type) param2;


declaring methods
Declaring methods

C++ syntax

void function(int x, int y, char z);

Object.function(x, y, z);

Objective-C syntax

-(void) method:(int)x, (int)y, (char)z;

[Object function:x, y, z];

-(return type) function_name: (type) p1, (type) p2, ***;

Apply function to Objectpassing parameters x,y,z

whats this and stuff
Whats this + and – stuff?
  • When declaring or implementing functions for a class, they must begin with a + or -
  • + indicates a “class method” that can only be used by the class itself. (they are like static methods in Java invoked on class itself)
  • - indicates “instance methods” to be used by the client program (public functions) –invoked on an object / class instance . (they are like regular methods in Java invoked on object)
  • Root class is NSObject
  • Inheritance is cumulative. A Square object has the methods and instance variables defined for Rectangle, Shape, Graphic, and NSObject, as well as those defined specifically for Square
inheritance cont
Inheritance (cont.)
  • Instance Variables: The new object contains not only the instance variables that were defined for its class, but also the instance variables defined for its super class, all the way back to the root class
  • Methods: An object has access not only to the methods that were defined for its class, but also to methods defined for its super class
  • Method Overriding: Implement a new method with the same name as one defined in a class farther up the hierarchy. The new method overrides the original; instances of the new class will perform it rather than the original
the interface
The Interface
  • The declaration of a class interface begins with the compiler directive @interface and ends with the directive @end

@interface ClassName:ItsSuperclass


instance variable declarations


method declarations


  • UIKit.framework for developing standard iOS GUIs (buttons etc.)
  • UITextField (user-entered text that brings up the keyboard)
  • UIFont
  • UIView
  • UITableView
  • UIImageView
  • UIImage
  • UIButton (a click-able button)
  • UILabel (a string of text on-screen)
  • UIWindow (main Window on iPhone)
ios programming
iOS programming
  • Event driven framework
  • Interface Designer has some extra macros for the code that act like hooks to variables;
    • IBAction - trigger events like mouse clicks
    • IBOutlet - captures outputs from events
  • These tags are not compiled (don't affect the code) but sit as an extra before variables that the Interface Designer can see.
start a new xcode ios project
Start a New XCode iOS Project
  • New Project → iPhone/iPad OS
  • Navigation-Based - “navigation controller” as used in Contacts app.
  • OpenGL ES - cut-down OpenGL
  • Tab Bar – app in style of iPod app.
  • Utility – Flipside app in style of stock quote app.
  • View-Based – single view that you draw into and display to screen.
  • Window-Based – basic app with a main window. (we will use this one for examples.)
some xcode items explored
Some Xcode items explored
  • An outlet defines a path between the code and the view that can be used to read and write values.
  • An action defines a method in your application that can be triggered via an event within a view, such as a touch or swipe.

IOS Development

  • The @property directive declares elements in a class that should be exposed via "getters" and "setters" (or accessors and mutators, if you prefer). Properties are defined with a series of attributes, most frequently nonatomic and retain on the iPhone.

IOS Development

  • The @synthesize directive creates simplified getters and setters, making retrieving and setting values of an object very simple.
  • @synthesize myLabel;
  • @synthesize firstNum;
  • @synthesize secNum;

IOS Development

ibaction docalculation id sender
  • -(IBAction)doCalculation:(id)sender;
  • Notice that the declaration includes a sender parameter with the type of id. This is a generic type that can be used when you don't know (or need to know) the type of object you'll be working with. By using id, you can write code that doesn't tie itself to a specific class, making it easier to adapt to different situations.
  • When creating a method that will be used as an action (like our doCalculation example), you can identify and interact with the object that invoked the action through the sendervariable (or whatever you decide to call it in your code). This will be handy if you decide to design a method that handles multiple different events, such as button presses from several different buttons.

IOS Development

let s plan our calculator app
Let’s Plan Our Calculator App
  • What will we need?
  • Comment it out?
  • What will be out properties?
  • What will be our actions?

IOS Development

your projects
Your Projects…
  • Intro to story boards
  • What Initial Layout will you choose?
  • What elements will give the best usability considering the interface? Will gestures or accelerometers be necessary?

IOS Development

frameworks needed
Frameworks Needed
  • For UI Stuff: #import <UIKit/UIKit.h>
  • For Basic Code Stuff: #import <Foundation/Foundation.h>
  • For Graphics
  • For GeoLocation#import <CoreLocation/CoreLocation.h> or #import <MapKit/MapKit.h>

IOS Development

apps in class
Apps in class…
  • We will do an App that stores something several different ways plist/sqlite/coredata
  • We may elect to use the latest icloud technology to store things
  • we will do a geo location app
  • we will do a multimedia app
  • All of these apps will have homework that extend on them and you are free to use all code for your projects…

IOS Development

for multimedia
For Multimedia:
  • #import <MediaPlayer/MediaPlayer.h>
  • #import <AVFoundation/AVFoundation.h>
  • #import <CoreAudio/CoreAudioTypes.h>
  • #import <CoreImage/CoreImage.h>

IOS Development

others we may need
Others we may need
  • #import <AddressBook/AddressBook.h>
  • #import <AddressBookUI/AddressBookUI.h>
  • #import <MessageUI/MessageUI.h>
  • #import <Social/Social.h>
  • #import <CoreMotion/CoreMotion.h>

IOS Development