Xcode & Swift: Introduction

Similar documents
Debugging and Profiling

Functions and Collections. Dr. Sarah Abraham

Swift. Introducing swift. Thomas Woodfin

CIS 130 Exam #2 Review Suggestions

SWIFT - CLOSURES. Global Functions Nested Functions Closure Expressions. Have a name. Capture values from enclosing function

Introduction to Programming Using Java (98-388)

ios Application Development Lecture 2: Seminar and Unit 1

SWIFT - FUNCTIONS. Function Declaration: It tells the compiler about a function's name, return type, and parameters.

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

COMP327 Mobile Computing Session:

ITP 342 Mobile App Dev. Functions

Xcode 6 and ios 8 What s New for Software Developers

Questions. Exams: no. Get by without own Mac? Why ios? ios vs Android restrictions. Selling in App store how hard to publish? Future of Objective-C?

Class 15. Object-Oriented Development from Structs to Classes. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

iphone Application Programming Lecture 3: Swift Part 2

Static Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1

Cellular Automata Language (CAL) Language Reference Manual

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Lecture 09: Data Abstraction ++ Parsing is the process of translating a sequence of characters (a string) into an abstract syntax tree.

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

BLM2031 Structured Programming. Zeyneb KURT

What s New in LLDB. Debug your way to fame and glory #WWDC15. Developer Tools. Session 402

Stanford CS193p. Developing Applications for ios. Fall CS193p. Fall

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

CSE341, Spring 2013, Final Examination June 13, 2013

CISC 1600 Lecture 3.1 Introduction to Processing

Comp 311: Sample Midterm Examination

SWIFT! init(title: String) { self.title = title } // required initializer w/ named parameter

Ruby: Introduction, Basics

Lecture08: Scope and Lexical Address

CSE341 Autumn 2017, Final Examination December 12, 2017

How to make a "hello world" program in Java with Eclipse *

COMP Summer 2015 (A01) Jim (James) Young jimyoung.ca

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)

CS Programming Languages: Scala

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Porting Objective-C to Swift. Richard Ekle

Optimizing Swift Performance Session 409

ENGR 102 Engineering Lab I - Computation

iphone Application Programming Lecture 3: Swift Part 2

Stanford CS193p. Developing Applications for ios. Winter CS193p. Winter 2017

M/s. Managing distributed workloads. Language Reference Manual. Miranda Li (mjl2206) Benjamin Hanser (bwh2124) Mengdi Lin (ml3567)

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

6.096 Introduction to C++ January (IAP) 2009

Recap: Functions as first-class values

ios Application Development Lecture 4: Navigation and Workflow

Syntax Errors; Static Semantics

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

Introductory ios Development

Programming Language Concepts, cs2104 Lecture 04 ( )

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Faculty of Engineering Computer Engineering Department Islamic University of Gaza C++ Programming Language Lab # 6 Functions

G Programming Languages - Fall 2012

Scala : an LLVM-targeted Scala compiler

Apple s new Swift language

Stanford CS193p. Developing Applications for ios. Spring CS193p. Spring 2016

CSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Ruby Containers, Blocks, and Procs

CSC 581: Mobile App Development Spring 2019

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

Chapter 3. More Flow of Control. Copyright 2008 Pearson Addison-Wesley. All rights reserved.

Classes. Logical method to organise data and functions in a same structure. Also known as abstract data type (ADT).

CSE341 Spring 2016, Final Examination June 6, 2016

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O

Compiler Construction

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 4

Object-oriented programming in...

Ruby: Introduction, Basics

COP4020 Programming Assignment 1 - Spring 2011

Lectures 5-6: Introduction to C

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Compiler Construction

XSEDE Scholars Program Introduction to C Programming. John Lockman III June 7 th, 2012

Object-Oriented Programming

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

COMP 208 Computers in Engineering

Pace University. Fundamental Concepts of CS121 1

A Fast Review of C Essentials Part I

ITP 342 Mobile App Dev. Animation

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

- HALF YEARLY EXAM ANSWER KEY DEC-2016 COMPUTER SCIENCE ENGLISH MEDIUM

Object-Oriented Programming

2 nd Week Lecture Notes

Lecture 5: Methods CS2301

Compiler Construction

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413

This exam is to be taken by yourself with closed books, closed notes, no calculators.

Finding Bugs Using Xcode Runtime Tools

PIC 10A. Review for Midterm I

The Substitution Model

G Programming Languages - Fall 2012

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

Working with classes and objects COSC346

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

CS 11 java track: lecture 1

Transcription:

Dr.-Ing. Thomas Springer M.Sc. Martin Weißbach

Concept You need Apple Computer Xcode 8 (ios device) Hands on course to learn how to program ios 1/1/0 means 45min lecture, 45min seminar introducing concepts and theory life coding 2

Modules and Exams Modules DSE-14-13, DSE-14-E14 INF-B-510, INF-B-520, INF-B-530, INF-B-540 INF-BAS4, INF-BI-1, INF-PM-FPA, INF-VERT4 Erasmus, (make sure that you can use the credits for your course of study) Credits 2 SWS 3 credits Exam Bachelor: oral 25min Master & Diplom: module exam Others: check module definition 3

Questions regarding lecture, ios, etc. martin.weissbach1@tu-dresden.de exam dates, credibility for your course of study, bureaucracy thomas.springer@tu-dresden.de 4

5

Xcode Navigator Panel October, 16th 2017 Project Navigator UtilitiesPanel Symbol Navigator File Inspector Find Navigator Quick Help Inspector Issue NavigatorDebug Area Test Navigator Right: Console Debug Navigator Breakpoint Navigator Report Navigator Left: Variables View 6

Xcode: Playground Just-In-Time evaluation of code chronologic depiction variables, executed command incl. loops etc. Useful for: algorithm development (each step performed is easily visible) test of Tests gaining familiarity with new APIs 7

Xcode: Playground Life Evaluation and History of Loops Left: Playground Code Editor Right: Life Evaluation of Source Code 8

Swift: Syntax & Control Structures 9

Variable Declaration var helloworld = Hello World var helloworld: String var red, green, blue: Double var red = 0.0, green = 0.0, blue = 1.0 helloworld = Welcome to the new World! 10

Constant Declaration let helloworld = Hello World! let red = 0.0, green = 0.0, blue = 1.0 helloworld = Welcome to the new World! compile-time error 11

Types String representation of sequences of characters var string = I am a string Dictionary<K, V> key-value store var dictionary = [ lang : Swift, version : 2.0 ] Array<T> ordered list of objects var array = [ Swift, Objective-C ] Set<T> unordered list ob objects var set = [ Swift, Objective-C ] 12

if-else, switch if <condition> { if <condition> { <statements> <statements> else { <alternatives> switch <considered_value> { case <value_0>: <response to value_0> case <value_1>, <value_2>: <response to value_1 and value_2> default: <otherwise> if <condition_0> { <statements_0> else if <condition_1> { <alternatives_0> else { <alternatives> 13

for, for-in, while, repeat-while for <initialization>; <condition>; <increment> { <statements> for element in arrayofelements { <statements> for (key, value) in dictionaryofelements { <statements> Swift 3 while <condition> { <statements> repeat { <statements> while <condition> 14

C-like for the Swift way for <initialization>; <condition>; <increment> { <statements> Since Swift 3 the closed range operator ( ) is used: for index in 1...10 { <statements> (1...10).forEach { print($0) <statements> 15

Functions / Methods Functions self-contained pieces of code each function has a name, used to identify and call the function a type, that consists of the function s parameter types and return type Methods is function, that is only within the scope, e.g. classes, structures or enumerations 16

Functions func fsig(p1: String, p2: Int) -> (ret1: Int, ret2: String) fsig( A String, 0) returns (ret1: 0, ret2: A String ) func noparam() -> Int noparam() returns 5 func noreturnv(param: String) -> () func noreturnv(param: String) noreturnv( Another String ) returns Void which is () 17

Argument Label func ex1(argumentlabel parametername: Any) ex1(argumentlabel: 5) func pow(basis: Int, exponent: Int) -> Int pow(basis: 5, exponent: 3) returns 125 func raisebase(_ base: Int, by exp: Int) -> Int raisebase(5, by: 3) returns 125 18

Inout Parameter used, when a function needs to modify variables outside of the function s scope only variables can be passed as inout parameters constants and literals are not allowed, because they cannot be modified func swapints(inout a: Int, inout b: Int){ let tmpa = a a = b b = tmpa var a = 5 var b = 10 swapints(&a,&b) 19

Methods functions bound to types and instances of types, respectively func examplemethod() -> String for instances of both value and reference types class func examplemethod() -> String type method for reference types static func examplemethod() -> String type method for value types 20

Closures similar to other languages lambdas capture and store references of any constant or variable from the context in which Closures are defined global and nested functions are special cases of closures 21

Forms of Closures global functions have a name and do not capture anything nested functions have a name and capture variables from their enclosing function closure expressions unnamed and capture values from their surrounding context 22

Syntax of Closures General Declaration Syntax: func example(source: Int, closure: (parameters) -> returnvalue) -> Int Definition of function expecting a closure as 2 nd parameter: func own_filter<t: SequenceType>(source: T, element: (T.Generator.Element) -> Bool) -> [T.Generator.Element] General Expression Syntax: { (parameters) -> returntype in // statements here Example Implementation: { (array: T, (element: Int) -> Bool in return element == 42 23

Classes, Structures, Enumerations Syntax & Semantics 24

Classes class ExampleClass: ExamplesSuperClass { var property_1: String let property_2 = 10.4 Reference Type Single Inheritance func method_1() -> Bool { <statements> Memory Management rules apply 25

Structures Value Type struct ExampleStructure { var width: Int var height: Int func plane() -> Int { return width * height No inheritance or Memory Management rules apply Best suited for data encapsulation 26

Enumerations Value Type enum Directions { case North case South case East case West group related values func oppositedirection() -> Directions { <statements> No inheritance or Memory Management rules apply 27

Behavior with let and var Reference and Value Types behave differently 28

Reference Types with let class Car { let ps: Int var numberplate: String let car = Car(ps: 310, numberplate: DD-XX-1234 ) car = Car(ps: 120, numberplate: M-XX-1234 ) car.ps = 410 car.numberplate = 30 car.numberplate = DD-XY-9876 29

Reference Types with var class Car { let ps: Int var numberplate: String var car = Car(ps: 310, numberplate: DD-XX-1234 ) car = Car(ps: 120, numberplate: M-XX-1234 ) car.ps = 410 car.numberplate = 30 car.numberplate = DD-XY-9876 30

Value Types with let struct Painting { let artist: String var price: Float let painting = Painting(artist: Aito, price: 5.99) painting = Painting(artist: Ashisu, price: 3.99) painting.artist = Fuwa painting.price = 5 painting.price = 7.99 31

Value Types with var struct Painting { let artist: String var price: Float var painting = Painting(artist: Aito, price: 5.99) painting = Painting(artist: Ashisu, price: 3.99) painting.artist = Fuwa painting.price = 5 painting.price = 7.99 32

Summary Reference Type let Value Type Reference Type var Value Type Reassignments Modify Mutable Properties Modify Immutable Properties 33

Protocols 34

Protocols declaration of methods and properties without providing an implementation can be adopted by a class, structure or enumeration types adopting a protocol are responsible for providing an implementation for the declared requirements of the protocol protocol ExampleProtocol { // Protocol definition class ClassType: ExampleProtocol { // Class definition 35