SWIFT BASICS

Similar documents
Swift. Introducing swift. Thomas Woodfin

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

Richard Mallion. Swift for Admins #TEAMSWIFT

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?

Jython. An introduction by Thinh Le

Functions and Collections. Dr. Sarah Abraham

Xcode 6 and ios 8 What s New for Software Developers

Scala, Your Next Programming Language

Getting Help. iphone Application Programming Lecture 3: Foundation Classes. Data Structures in Objective C. Online Documentation.

iphone Application Programming Lecture 3: Foundation Classes

Swift. Mobile Application Development in ios School of EECS Washington State University Instructor: Larry Holder

Introduction to Swift. Dr. Sarah Abraham

CS 371L - Mobile Computing (ios) Dr. William C. Bulko. CS 371L Mobile Computing (ios) Introduction

Stanford CS193p. Developing Applications for ios. Winter CS193p! Winter 2015

Porting Objective-C to Swift. Richard Ekle

An introduction to Swift. Sasha

welcome to BOILERCAMP HOW TO WEB DEV

Objective-C. Stanford CS193p Fall 2013

SWIFT & #IOExtendedCLT, 18th May 2016

Functional Reactive Programming on ios

COMP-520 GoLite Tutorial

ios 8 SDK Development

When Swift met classic algorithms and data structures. Caveats & Tips

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

BEGINNING ios PROGRAMMING

ITP 342 Mobile App Dev. Animation

MEAP Edition Manning Early Access Program ios Development with Swift Version 2

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING

Mobile Application Development

Welcome to CS50 section! This is Week 10 :(

Assignment II: Foundation Calculator

Beginning IOS 4 Application Development By Wei-Meng Lee READ ONLINE

Scala : an LLVM-targeted Scala compiler

CSC 581: Mobile App Development Spring 2019

Maxime Defauw. Learning Swift

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

Introduction to Python

ITP 342 Mobile App Dev. Functions

Intro to Development for ios. Dave Koziol Arbormoon Software, Inc.

Ruby: Introduction, Basics

IOS 9 App Development Essentials: Learn To Develop IOS 9 Apps Using Xcode 7 And Swift 2 By Neil Smyth

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Collections & Memory Management. Lecture 2

Apple s new Swift language

Topics in Mobile Computing

Monday, 1 November The ios System

Table of Contents EVALUATION COPY

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

pyprika Documentation

CMSC 330: Organization of Programming Languages. Rust Basics

Publisher v3 Documentation

Senthil Kumaran S

Contents. Preface. Introduction. Introduction to C Programming

John McCarthy IBM 704

ios Application Development Lecture 2: Seminar and Unit 1

First Programming Language in CS Education The Arguments for Scala

Learn Ruby On Rails For Web Development Learn Rails The Fast And Easy Way

Programming: C ++ Programming : Programming Language For Beginners: LEARN IN A DAY! (Swift, Apps, Javascript, PHP, Python, Sql, HTML) By Os Swift

SAMS Programming - Section C. Lecture 1: Introduction + Basic Building Blocks of Programming

Python in 10 (50) minutes

About Python. Python Duration. Training Objectives. Training Pre - Requisites & Who Should Learn Python

Programming in Python

CS193p Spring 2010 Thursday, April 29, 2010

Introductory ios Development

My First Command-Line Program

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

Python Tutorial. Day 1

Course Title: Python + Django for Web Application

Xcode & Swift: Introduction

COMP327 Mobile Computing Session: Lecture Set 1a - Swift Introduction and the Foundation Framework Part 2

Using Scala in CS241

Python Basics. Lecture and Lab 5 Day Course. Python Basics

Stanford CS193p. Developing Applications for iphone 4, ipod Touch, & ipad Spring Stanford CS193p Spring 2011

How to Quickly Type Emoji on Mac with a Keyboard Shortcut Folded Hands. Two hands placed firmly together, meaning please or

Swift: Programming, Master's Handbook: A TRUE Beginner's Guide! Problem Solving, Code, Data Science, Data Structures & Algorithms (Code Like A PRO

CS 47. Beginning iphone Application Development

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

CS2304: Python for Java Programmers. CS2304: Sequences and Collections

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml

Gerontechnology II. Collecting Smart Phone Sensor Data for Gerontechnology. Using ios

Lecture content. Course goals. Course Introduction. TDDA69 Data and Program Structure Introduction

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

Go vs. Swift: The Languages of The Modern Tech Giants

Samsung Galaxy S3 Repair Video Call Apple Tv

Pace University. Fundamental Concepts of CS121 1

Duration 5 days (For basic crowd 5+3days needed)

Mobile Application Programming. Objective-C Classes

Seminar on Languages for Scientific Computing Aachen, 6 Feb Navid Abbaszadeh.

IPHONE. Development Jump Start. phil nash levelofindirection.com

Try the following example using Try it option available at the top right corner of the following sample code box:


ios Development - Xcode IDE

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

Kevin van Vechten Core OS

Go Forth and Code. Jonathan Gertig. CSC 415: Programing Languages. Dr. Lyle

Presented By Jason Pinshower Indian Trails Public Library District

Binghamton University. CS-211 Fall Pointers to Pointers

BLM2031 Structured Programming. Zeyneb KURT

ITP 342 Mobile App Development. Data Persistence

Introduction to Python: Data types. HORT Lecture 8 Instructor: Kranthi Varala

Transcription:

SWIFT BASICS jhkim@dit.ac.kr www.facebook.com/jhkim3217 2014. 7. 19

Reference Swift Guide, 2014 AppCode.com Swift Tutorial: A Quick Start, Ray Wenderlich

background new programming language for ios, OS X Apps Ruby, Python, Go v.s. Objective-C Fast, Modern, Safe, Interactive Shorter, Cleaner, Easier to read ( Javascript ) user friendly to new programmers

PLAYGROUND

Variable, Constants, var let Type Inference var numberofrow = 30 let maxnumberofrows = 100 var = Have fun // emoji character const int count = 10; // double price = 23.55; NSString *mymessage = @ Obj-C is not dead yet ;

let count = 10 // count is inferred to be type Int var price = 23.55 // price is inferred to be type Double var mymessage = Swift is the future // mymessage is inferred to be type String var mymessage : String = Swift is the future

var mymessage = No semicolon is needed

String type is fully Unicode-compliant // immutable String let dontmodifyme = You can t modify this string // mutable String var modifyme = You can modify this string String manipulation let firstmessage = Swift is awesome. let secondmessage = What do you think? var message = firstmessage + secondmessage

// Objective-C NSString *firstmessage = @ Swift is awesome. ; NSString *secondmessage = @ What do you think? NSString *message = [NSString stringwithformat:@ %@%@, firstmessage, secondmessage]; NSLog(@ %@, message);

var string1 = Hello var string2 = Hello if string1 == string2 { println( Both are the same ) else { println( Both are different )? // Obj-C isequaltostring: method

// Objective-C, store any type of objects NSArray *recipes = @[@, @, @, @, @ ]; // Swift, store items of the same type var recipes = [" ", " ", " ", " ", " ", ] var recipes : String[] = [" ", " ",, " ", " "] // recipes.count will return 5 var numberofitems = recipes.count

// add items recipes += // add multiple items recipes += [,, ] // access or change a item in an array var recipeitem = recipes[0] recipes[1] = // change a range of values recipes[1 3] = [,, ] println(recipes)

// Objective-C NSDictionary *companies = @{@ APPL : @ Apple, @ GOOG : @ Google, @ FB : @ Facebook ; // Swift var companies = [ APPL : Apple, GOOG : Google, FB : Facebook ]; var companies: Dictionary<String, String> = [ APPL : Apple, GOOG : Google, FB : Facebook ];

// Iteration for (stockcode, name) in companies { println( \(stockcode) = \(name) for stockcode in companies.keys { println( Stock code = \(stockcode) ) for name in companies.values { println( Companies name = \(name) ) // add a new key-value pair to Dictionary companies[ TWTR ] = Twitter

// define a class class Recipe { var name: String = var duration: Int = 10 var ingredients: String[] = [ egg ] // optional :? class Recipe { var name:string? // assign default value of nil var duration: Int = 10 var ingredients: String[]? // create a instance var recipeitem = Recipe()

// access or change the property variable recipeitem.name = recipeitem.duration = 30 recipeitem.ingredients = [ olive oil, salt, onion ]

// Objective-C @interface SimpleTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> // Swift class SimpleTableViewController : UIViewController, UITableViewDelegate, UITableViewDataSource

define methods in class, structure or enumeration func keyword class TodoManager { func printwlecomemessage() { println( Welcome to My ToDo List ) // Swift method call todomanager.printwelcomemessage() // Objective-C [todomanager printwelcomemessage];

// method arguments, return value class ToDoManager { func printwelcomemessage(name:string) -> Int { println( Welcome to \(name) s todo List ) return 10 var todomanager = TodoManager() let numberoftodoitem = todomanager.printwelcomemessage( Superman) println(numberoftodoitem)

for loops for i in 0..5 { println( index = \(i) ) for var i=0; i<5; i++ { printf( index = \(i) )

for i in 0 5 { println( index = \(i) ) for var i=0; i<=5; i++ { printf( index = \(i) )

if-else var bookprice = 1000 if bookprice >= 999 { println( Hey, the book is expensive ) else { println( Okey, I can buy it )

switch // break swicth recipename { case : println( ) case : println( ) case : println( ) default: println( )

// range matching(.., ) var speed = 50 switch speed { case 0: println( stop ) case 0 40: println( slow ) case 41 70: println( normal ) case 71..101 println( fast ) default: println( not classified yet )

multiple values as a single compound value any value of any type in the tuple // create tuple let company = ( AAPL, Apple, 93.5) // decomposing let (stockcode, companyname, stockprice) = company println( stock code = \(stockcode) ) println( company name = \(companyname) ) println( stock price = \(stockprice) )

// dot notation let product = (id: AP234, name: iphone6, price:599) println( id = \(product.id) ) println( name = \(product.name) ) println( price = USD\(product.price) )

// return multiple values in a method class Store { func getproduct(number: Int)->(id: String, name: String, price: Int) { var id = IP435, name = imac, price = 1399 switch number { case 1: id = AP234 name = iphone 6 price = 599 case 2: id = PE645 name = ipad Air price = 499 default: break return(id, name, price) //call a method let store = Store() let product = store.getproduct(2) println( id = \(product.id) ) println( name = \(product.name) ) println( price = USD\(product.price) )

Enjoy Swift