Introduction to Objective-C and Xcode (Part 1) FA 175 Intro to Mobile App Development.

Slides:



Advertisements
Similar presentations
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Advertisements

Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
The Web Warrior Guide to Web Design Technologies
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 1 Tariq Aziz and Kevin Jones.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Introduction to Computers and Programming Lecture 3: Variables and Input Professor: Evan Korth New York University.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
Compunet Corporation Programming with Visual Basic.NET GUI Week # 11 Tariq Ibn Aziz.
ASP.NET Programming with C# and SQL Server First Edition
1 Chapter 1 Tour of Access. 1 Chapter Objectives Start and exit Microsoft Access Open and run an Access application Identify the major elements of the.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Microsoft Visual Basic 2005 CHAPTER 12 Cell Phone Applications and Web Services.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
Sprite Animation CSE 391 Fall 2012 Tony Scarlatos.
Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Introduction to Objective-C and Xcode (Part 3) FA 175 Intro to Mobile App Development.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
Objective C Basics. It’s C with Some Extras!  Cross Platform language  Mac  Linux/UNIX  Windows  Layer above C (Superset)  Adds Object-Oriented.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Classes CS 21a: Introduction to Computing I First Semester,
Using Xcode A Beginner’s Tutorial Erin Green. This tutorial will walk you through Xcode, a software development tool for Apple’s iOS applications – We.
Managing Multiple Views and Segues FA 172 Intro to Mobile App Development.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
University of Sunderland CIF 102/FIF102 Fundamentals of DatabasesUnit 15 Programming in Microsoft Access using VBA Using VBA to add functionality.
Introduction to Programming with RAPTOR
+ An Intro To Xcode By Sarah Montroy. + What is Xcode?
Applications Development
Introduction to Objective-C and Xcode (Part 5) FA 175 Intro to Mobile App Development.
Sounds, Images, and Text FA 172 Intro to Mobile App Development.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
Programming with Microsoft Visual Basic th Edition
1 Reverse a String iPhone/iPad, iOS Development Tutorial.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Folio3 IPhone Training Session 2 Testing App on device Presenter: Imam Raza.
Introduction to Objective-C and Xcode (Part 4) FA 175 Intro to Mobile App Development.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
A Sample Program #include using namespace std; int main(void) { cout
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Introduction to Programming and App Inventor. Introduction What is a computer program? Introducing App Inventor Getting hands on with App Inventor.
Dive Into® Visual Basic 2010 Express
Chapter 2: The Visual Studio .NET Development Environment
Visual programming Chapter 1: Introduction
An Introduction to Computers and Visual Basic
Introduction to C++ Programming
CIS16 Application Development Programming with Visual Basic
An Introduction to Computers and Visual Basic
Classes CS 21a: Introduction to Computing I
CSC 581: Mobile App Development
Presentation transcript:

Introduction to Objective-C and Xcode (Part 1) FA 175 Intro to Mobile App Development

Next four sessions Crash course in Objective-C Tutorial on the Xcode development environment

What we have done so far Created simple Xcode projects – HelloWorld App and TextShuffler App – Single-View applications with labels, text fields, and buttons Walked through the creation of a more complex application – CoffeeCatalog App – App that used a navigation controller, multiple views, and segues – Required more complex code

Objectives of the next sessions Understand the rules of the Objective-C programming language – For beginners, learn programming – For programmers, learn a new language Learn the Xcode development environment and its various features

Objective-C, Xcode, and iOS Objective-C: programming language Xcode: development environment iOS: operating system for (Apple) mobile devices Apps that run on devices under the iOS platform are developed in Objective-C using Xcode

Xcode projects An Xcode project is a collection of settings, programs and resources – Settings indicate values for various parameters that direct how the project is built – Programs are files written using Objective-C code – Resources are other files such as images and data files that are required to build the project and execute the corresponding application All the files of an Xcode project are contained in a specific folder

HelloWorld App revisited Created using the Single-View template – A template provides pre-created files/programs to simplify development Settings – e.g., project name (HelloWorld), target device (IPhone), deployment target (iOS 6.0), … Interface was built and additional code was supplied to produce the intended app – Label, button, and text field were added through the interface builder (Xcode feature) – Code added caused text to be copied from the text field to the label through a button click

Programs and programming What is a program? – Sequence of instructions that processes data on a computer What is a programming language? – Rules for writing a program Most basic components – Data: variables and types – Instructions: statements

Variables Variables hold data/values Variables are named Variables are of a particular type – Examples of types: int (number), NSString (string) – Types restrict the values that a variable can hold Objective-C variable declaration example: – int counter; – defines a variable called counter that holds an integer value

Some common types Whole number – int – Sample values: 123, -8, 0 Floating point number – double – Sample values: 2.75, , 1.23e4 Switch/toggle – BOOL – Values: YES, NO String of characters – NSString – @":-)"

Working with variables Declaration – double unitPrice, total; int itemCount; NSString *message; Assignment – unitPrice = ; itemCount = 5; total = itemCount*unitPrice; message world.";

Working with variables Output (using NSLog function) – of items: %d", itemCount); message); x %f = %8.2f", itemCount,unitPrice, total); Output (through an outlet connection) – self.label.text = message;

Testing some code Create an Xcode project (Single-View template), add a button to the view on the storyboard, and then create an action outlet for the button named “go:” In the.m source file, supply the following code within the go: method (between the { }) – int itemCount; double unitPrice, total; NSString *message code"; itemCount = 5; unitPrice =125.75; total = itemCount*unitPrice; message); of items: %d", itemCount); message); x %f = %8.2f", itemCount, unitPrice, total);

Code int itemCount; double unitPrice, total; NSString *message code”; itemCount = 5; unitPrice =125.75; total = itemCount*unitPrice; message); of items: %d", itemCount); message); x %f = %8.2f", itemCount, unitPrice, total);

Summarizing what we have done We wrote a sequence of instructions (or statements) and executed them through Xcode and the simulator The statements involved variables – Declarations: established names and types for the variables – Assignment statements: assigned values to the variables – Function calls: displayed the values of the variables Note: these statements follow Objective-C rules/syntax and conventions

Syntax of statements Variable declaration: – ; – * ; Assignment: – = ; NSLog function call: – NSLog(,, … ); Note that all of the above statements end with a semicolon

Accepted conventions A name used in an Objective-C program is a sequence of letters and digits, but should start with a letter – Examples: Product, price, section123, totalAmt – Note that names (also called identifiers) are case sensitive Convention for variable names in Objective-C: – Start with a lower-case letter – If the name comprises multiple words, capitalize the first letters of succeeding words – Examples: unitPrice, totalAmountInPesos

Expressions and operators Assignment statements may involve complex operations, for example: totalTax = (income )*0.32; An expression is a combination of values, variables, operators, and computations through methods and functions Operators: + - * / ( ) and many others expression

NSLog NSLog causes output to be displayed in the debug window of Xcode – Very useful during development NSLog(,, … ); The first argument of the function is a format string specifying what and how a value is displayed – % in the string specifies placeholders in the output – %d for integers, %f for doubles, for strings Succeeding arguments indicate the values to be displayed

NSLog examples of items: %d", itemCount); number of items: 5 has %d hands ", name, numHands); Andrei has 2 hands x %f = %8.2f", itemCount,unitPrice, total); 7 x =

Converting between types int num; double val; NSString *s; Between int and double, done via straightforward assignment, but there is truncation when going from double to int – val = num; // ok, no problem: 123 becomes – num = val; // truncation occurs: 5.67 becomes 5 How about converting between numbers and strings? – Use conversion methods

Between strings and numbers string to int – num = [s intValue]; string to double – val= [s doubleValue]; int to string – s = [NSString stringWithFormat:"%d",num]; double to string – s = [NSString stringWithFormat:"%f",val]; Similar to NSLog

Tip of the iceberg The apps we have written early on contain a lot more code than what we have discussed so far Concepts that will be discussed in the next sessions – Classes – Properties and methods – Header and implementation files The statements we have learned (declaration, assignment, function call) enable us to write code to specify methods

Back to Xcode Interface Builder Managing connections between Objective-C code and the user interface

The Interface Builder in Xcode The user interface is an essential component of an app – In many other platforms, separate “code” is required for an interface, sometimes written by the developer In Xcode, this interface is created visually through the Interface Builder of Xcode using drag and drop commands – storyboard, views, controls

The Interface Builder in Xcode The components of an interface are associated with the code you write through connections – Outlet connections enable retrieval of data to and from controls like labels or text fields – Action connections specify methods to be invoked when an event occurs such as a button click Outlets and actions appear as Objective-C code in the.h and.m files – But the associations are carried out separately within Xcode (control-drag actions between interface and code)

IB and connections storyboard, controller, view, controls In ViewController.m … ViewController.h:

Managing connections Click on view controller icon at the bottom of the storyboard Then click on connections inspector Ensure connections are as intended – Remove stray connections (usually resulting from name changes and dragging errors)

Exercise Download and unzip the HelloWorld app you submitted early in the semester Rename the property you associated with the label Rebuild and execute the project and fix issues accordingly – Open connections inspector to manage connections

Summary Objective-C basics: variables, computation, and simple statements Xcode and Interface Builder: connections