UFCFX5-15-3Mobile Device Development Swift Basics.

Slides:



Advertisements
Similar presentations
3 Copyright © 2005, Oracle. All rights reserved. Basic Java Syntax and Coding Conventions.
Advertisements

IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
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.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
UFCFX5-15-3Mobile Device Development iOS Development Framework.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CMT Programming Software Applications
B.Sc. Multimedia ComputingMultimedia Authoring Introduction to ActionScript 3.0.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
UFCFX5-15-3Mobile Device Development iOS Development Review.
Principles of Procedural Programming
String Escape Sequences
Introduction to C++ Programming
Chapter 9 Interactive Multimedia Authoring with Flash - Introduction to Programming “Computers and Creativity” Richard D. Webster, COSC 109 Instructor.
Programming Languages
High-Level Programming Languages: C++
CIS Computer Programming Logic
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
Web Services Week 2 Aims: Getting started with creating simple C# applications within Visual Studio.NET Objectives: –An introduction to the syntax of C#.NET.
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
1 C++ Syntax and Semantics, and the Program Development Process.
JavaScript Syntax, how to use it in a HTML document
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6: Transition to Java Programming with Alice and Java First Edition.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Arithmetic, Class Variables and Class Methods Week 11
Numeric Data Types There are six numeric data types: byte, short, int, long, float, and double. Sample variable declarations: int i, j, k; float numberOne,
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Computer Programming for Engineers
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Swift. Introduced in 2014 Replaces Objective-C as “recommended development language” “safer, succinct, readable” Emphasizes type safety.
Object Oriented Programming Object and Classes Lecture 3 MBY.
Arrays What is an array… –A data structure that holds a set of homogenous elements (of the same type) –Associate a set of numbers with a single variable.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
CGS 3066: Web Programming and Design Spring 2016 Introduction to JavaScript.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Topics for today: 1.Comments 2.Data types 3.Variable declaration.
What is an object?. What Makes an Object? An object has identity (it acts as a single whole). Every object has a name that identifies what it is. Ex.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
ActionScript Programming Help
CGS 3066: Web Programming and Design Spring 2017
Definition of the Programming Language CPRL
Mobile Device Development
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Chapter 10 Programming Fundamentals with JavaScript
Introduction to the C Language
Topic: Python’s building blocks -> Variables, Values, and Types
Computing Fundamentals
iOS Development Framework
Programming for Mobile Technologies
Introduction to Scripting
Introduction to the C Language
Chapter 10 Programming Fundamentals with JavaScript
Java Tutotrial for [NLP-AI] 2
Chapter # 2 Part 2 Programs And data
JavaScript: Introduction to Scripting
Presentation transcript:

UFCFX5-15-3Mobile Device Development Swift Basics

UFCFX5-15-3Mobile Device Development Agenda Swift in the Context of other Programming Languages Variable declaration, Typing and Assignment Program Output and Formatting Generating Random Numbers Data Structures: Arrays and Dictionaries Function Definitions Structure Declaration Class Declaration and Instantiation

UFCFX5-15-3Mobile Device Development The Swift Programming Language Variable declaration syntax has similarities with JavaScript and ActionScript Swift features several programming constructs from other languages including ObjectiveC and Smalltalk Swift borrows concepts from a number of programming paradigms, e.g. procedural and object-oriented programming and is therefore a multi-paradigm programming environment Swift allows type inference e.g. loose typing Swift programming statements do not required line ending characters such as semicolons

UFCFX5-15-3Mobile Device Development Variable Declaration and Assignment var aNumber // inferred (loose) typing - no statement ending i.e. ; or var aNumber:Int // uppercase I for Integer! aNumber = 5 // variable assignment

UFCFX5-15-3Mobile Device Development Constant Declaration Constant declaration uses the let keyword let PI =

UFCFX5-15-3Mobile Device Development Outputting Comments using println println ”Hello World”

UFCFX5-15-3Mobile Device Development Value Output with Comments var firstNumber:Int var secondNumber:Int var answer:Int firstNumber = 5 secondNumber = 14 answer = firstNumber + secondNumber println("The answer is:\(answer)") // syntax for comment and output

UFCFX5-15-3Mobile Device Development Random Number Generator ( arc4random_uniform(10)) Int(arc4random_uniform(10)) // integer

UFCFX5-15-3Mobile Device Development Random Number Generation var firstNumber:Int var secondNumber:Int var answer:Int firstNumber = Int(arc4random_uniform(10)) secondNumber = Int(arc4random_uniform(10)) answer = firstNumber + secondNumber println("The answer is:\(answer)”)

UFCFX5-15-3Mobile Device Development Swift Functions ‘func’ // function definition func addTwoInts(numberOne: Int, numberTwo:Int)-> Int { return numberOne + numberTwo } // function call with variables from earlier example answer = addTwoInts(firstNumber, secondNumber) println(“The sum of the two numbers is \(answer)”) println("The sum of \(firstNumber) + \(secondNumber) is:\(answer)")

UFCFX5-15-3Mobile Device Development Array Declaration var arrayOfIntegers:[Int] = [1,2,3,4,5,6,7,8,9,10] // print out all the numbers in the array for(number) in arrayOfIntegers{ println(number) }

UFCFX5-15-3Mobile Device Development Dictionaries (Keys and Values) let interestingNumbers = [ "Prime":[2, 3, 5, 7, 11, 13], "Fiboncacci": [1, 1, 2, 3, 5, 8], "Square":[1, 4, 9, 16, 25], ] for(kind, numbers) in interestingNumbers{ println(kind, numbers) } // output (Square, [1, 4, 9, 16, 25]) (Fiboncacci, [1, 1, 2, 3, 5, 8]) (Prime, [2, 3, 5, 7, 11, 13])

UFCFX5-15-3Mobile Device Development Swift Structures (struct) struct Resolution { var width = 1024 var height = 768 } //Resolution is now a new Swift type

UFCFX5-15-3Mobile Device Development Swift Class Definition class VideoMode{ var resolution = Resolution()// struct type var interlaced = false var frameRate = 0.0 var name: String? //? Infers optional type } //Resolution is used as type in the class definition

UFCFX5-15-3Mobile Device Development Creating Instances of a Structure and Class let aResolution = Resolution() // struct instance let aVideoMode = VideoMode()// class instance // accessing properties println(“The width of aResolution is \(aResolution.width)”) // prints “The width of aResolution is 1024”

UFCFX5-15-3Mobile Device Development Setting Properties of a Class and Structure // set the video mode resolution in the class struct aVideoMode.resolution.width = 1280 println(“The width of aVideoMode is now \(aVideoMode.resolution.width )”) // prints “The width of aVideoMode is now 1280”

UFCFX5-15-3Mobile Device Development Summary Swift is new programming language which draws syntax and structures from other well - established languages. Swift uses inferred (loose) typing, its basic syntax is similar to JavaScript and ActionScript 3.0 Swift is only currently available for the OSX platform via Xcode 6.x There are currently at least two online portals which provide compilation of Swift program code The Apple Developer Portal provides language documentation and resources such as the Swift Language and Cocoa with Swift as ebooks.