CS5530 Mobile/Wireless Systems Swift

Similar documents
CS1150 Principles of Computer Science Midterm Review

CS1150 Principles of Computer Science Introduction (Part II)

Eastern Mediterranean University School of Computing and Technology Information Technology Lecture2 Functions

The Java if statement is used to test the condition. It checks Boolean condition: true or false. There are various types of if statement in java.

CS1150 Principles of Computer Science Loops

DECISION CONTROL CONSTRUCTS IN JAVA

CS1150 Principles of Computer Science Introduction

Groovy Programming Language. Duration : 5 days. Groovy Getting Started. Groovy Big Picture. Groovy Language Spec. Syntax.

Laboratory #13: Trigger

Lab 1 - Calculator. K&R All of Chapter 1, 7.4, and Appendix B1.2

Lab 1 - Calculator. K&R All of Chapter 1, 7.4, and Appendix B1.2 Iterative Code Design handout Style Guidelines handout

CS1150 Principles of Computer Science Methods

- Replacement of a single statement with a sequence of statements(promotes regularity)

COP2800 Homework #3 Assignment Spring 2013

Programming Project: Building a Web Server

CS1150 Principles of Computer Science Methods

REFWORKS: STEP-BY-STEP HURST LIBRARY NORTHWEST UNIVERSITY

Iteration Part 2. Review: Iteration [Part 1] Flow charts for two loop constructs. Review: Syntax of loops. while continuation_condition : statement1

Java 8 Programming and Object Oriented Essentials for Developers New to OO (5 Days)

CS1150 Principles of Computer Science Boolean, Selection Statements (Part II)

Create Your Own Report Connector

These tasks can now be performed by a special program called FTP clients.

To start your custom application development, perform the steps below.

Whitepaper. Migrating External Specs to AutoCAD Plant 3D. Set Up the Required Folder Structure. Migrating External Specs to AutoCAD Plant 3D

C++ Reference Material Programming Style Conventions

LAB 7 (June 29/July 4) Structures, Stream I/O, Self-referential structures (Linked list) in C

WinEst 15.2 Installation Guide

Enterprise Chat and Developer s Guide to Web Service APIs for Chat, Release 11.6(1)

CS1150 Principles of Computer Science Final Review

Lab 4. Name: Checked: Objectives:

TRAINING GUIDE. Overview of Lucity Spatial

Please contact technical support if you have questions about the directory that your organization uses for user management.

Development Workbench- Screen Development II Oracle FLEXCUBE Universal Banking Release

Summary. Server environment: Subversion 1.4.6

Oracle FLEXCUBE Universal Banking Development Workbench- Screen Development II

Element Creator for Enterprise Architect

Ephorus Integration Kit

Element Creator for Enterprise Architect

Assignment #5: Rootkit. ECE 650 Fall 2018

Stock Affiliate API workflow

The programming for this lab is done in Java and requires the use of Java datagrams.

UiPath Automation. Walkthrough. Walkthrough Calculate Client Security Hash

Arius 3.0. Release Notes and Installation Instructions. Milliman, Inc Peachtree Road, NE Suite 1900 Atlanta, GA USA

CodeSlice. o Software Requirements. o Features. View CodeSlice Live Documentation

History of Java. VM (Java Virtual Machine) What is JVM. What it does. 1. Brief history of Java 2. Java Version History

INSERTING MEDIA AND OBJECTS

SOLA and Lifecycle Manager Integration Guide

Chapter 1 Introduction. What is a Design Pattern? Design Patterns in Smalltalk MVC

Step- by- Step Instructions for Adding a HotPot Activity 1. Click the Turn editing on button on the course home page.

Quick start guide: Working in Transit NXT with a PPF

Longitude Release Notes

EView/400i Management Pack for Systems Center Operations Manager (SCOM)

Project #1 - Fraction Calculator

Aras Innovator 11. Client Settings for Chrome on Windows

Introduction to Eclipse

ME Week 5 Project 2 ilogic Part 1

PL-2302 Mac OS Driver MAC/PC and PC/MAC Communication Software

Enabling Your Personal Web Page on the SacLink

Aras Innovator 11. Client Settings for Chrome on Windows

OO Shell for Authoring (OOSHA) User Guide

UBC BLOGS NSYNC PLUGIN

CS4500/5500 Operating Systems Processes

SPAR. Workflow for Office 365 User Manual Ver ITLAQ Technologies

CaseWare Working Papers. Data Store user guide

Installing Photran with Eclipse (MinGW or Cygwin)

Preparation: Follow the instructions on the course website to install Java JDK and jgrasp on your laptop.

The Login Page Designer

Relational Operators, and the If Statement. 9.1 Combined Assignments. Relational Operators (4.1) Last time we discovered combined assignments such as:

CS5530 Mobile/Wireless Systems Android UI

INSTALLING CCRQINVOICE

Software Toolbox Extender.NET Component. Development Best Practices

Getting Started with the Web Designer Suite

Amyuni Document Converter

Querying Data with Transact SQL

Product Documentation. New Features Guide. Version 8.7.5/XE6

Relius Documents ASP Checklist Entry

UiPath Automation. Walkthrough. Walkthrough Calculate Client Security Hash

JavaScript for Developers

Maximo Reporting: Maximo-Cognos Metadata

Syntactically Awesome StyleSheets. CSS extension that adds power and elegance to the basic language

NiceLabel LMS. Installation Guide for Single Server Deployment. Rev-1702 NiceLabel

RTX includes new functionality, see the product Release Notes for a full list of new features.

RISKMAN REFERENCE GUIDE TO USER MANAGEMENT (Non-Network Logins)

CUSTOM CONTROLS. Pieter Saelens Henri Reterink. Building for the future. Better, faster, everywhere.

Infrastructure Series

MyUni Adding Content. Date: 29 May 2014 TRIM Reference: D2013/ Version: 1

Sircon User Guide A Guide to Using the Vertafore Sircon Self-Service Portal


Cisco Tetration Analytics, Release , Release Notes

Lab 0: Compiling, Running, and Debugging

Structure Query Language (SQL)

UBPartner Product Release Note XBRL Toolkit, XCT, XRT, XVT Version 2.9. February, UBPartner. Revision 1. Phone:

OATS Registration and User Entitlement Guide

Technical Paper. Installing and Configuring SAS Environment Manager in a SAS Grid Environment with a Shared Configuration Directory

I - EDocman Installation EDocman component EDocman Categories module EDocman Documents Module...2

Integrating QuickBooks with TimePro

Compliance Guardian 4. User Guide

AngularJS. Unit Testing AngularJS Directives with Karma & Jasmine

DocAve 6 Granular Backup and Restore

Admin Report Kit for Exchange Server

Transcription:

Mbile/Wireless Systems Swift Yanyan Zhuang Department f Cmputer Science http://www.cs.uccs.edu/~yzhuang UC. Clrad Springs

cat annunce.txt_ imacs remte VNC access VNP: http://www.uccs.edu/itservices/services/netwrk-andinternet/vpn.html VNC passwrd: cs5530 Please save data t Z Please d nt use imacs in Library IT will upgrade 2

Swift What is it? A new prgramming language fr Apple prducts } ios (ipds, iphnes, ipads, etc.), macos, watchos, tvos, future } Currently at versin 3 T see yur versin: xcrun swift -versin Apple Swift versin 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1) } Open surce Based n Objective-C and C. } Classes, instances, prperties, methds, inheritance, etc. 3

Swift Requires an Apple prduct fr develpment } Air, MacBk, MacBk Pr, imac, itrashcan (MacPr) Requires the Xcde develpment envirnment, Apple nly. Resurces at: } https://develper.apple.cm/ 4

Xcde Playgrund An interactive wrk envirnment that allws yu update values real-time and see results. A prject ptin in Xcde. New fr ipad ios 10!!! 5

Xcde Playgrund 6

Swift Quick verview f the language Assignments Cntrl Flw Functins and Clsures Objects and Classes Enumeratins and Structures Prtcls Errr Handling 7

Swift - Overview Dn t need t imprt a separate library fr functinality like input/utput r string handling. Cde written at glbal scpe is used as the entry pint fr the prgram, s yu dn t need main(). Dn t need t write semiclns at the end f every statement. Excerpt Frm: Apple Inc. The Swift Prgramming Language (Swift 3.0.1). ibks. https://itun.es/ca/jeuh0.l 8

Swift - Assignments Key wrd Descriptin let var Types can be inferred Can be explicit NO implicit type cnversins } Values in strings by using a \ let apples = 3 Used fr cnstants. Des nt need t be knwn at cmpile time but must be assigned a value exactly nce. Used fr variables. let applysummary = I have \(apples) apples. 9

Swift - Assignments Key wrd let var Descriptin Used fr cnstants. Des nt need t be knwn at cmpile time but must be assigned a value exactly nce. Used fr variables. Types can be inferred Can be explicit NO implicit type cnversins } Values in strings by using a \ let apples = 3 let applysummary = I have \(apples) apples. } Values are never implicitly cnverted t anther type. If need t cnvert a value t a different type, explicitly make an instance f the desired type. The Swift Prgramming Language (Swift 3.0.1). 10

Swift - Assignments Assignments Dictinaries and arrays use [] var shppinglist = [ hp, apple, micrsft ] shppinglist[1] = Lenv var ccupatins = ["Malclm": "Captain", "Kaylee": "Mechanic"] ccupatins["jayne"] = "Public Relatins Empty arrays r dictinaries let emptyarray = [String]() Let emptydictinary = [String: Flat]() If type infrmatin can be inferred, can write an empty array as [] and an empty dictinary as [:] Data Types Typical data types available. } String, Flat, Duble, Bl, Int/Uint, Character, Optinal 11

Swift Cntrl Flw Keywrd if, switch fr-in, fr, while, repeat-while Fr/if example Descriptin If cnditin must be explicit if scre {..} is an errr Used fr cnditinals. Parenthesis arund variable are ptinal. Braces arund cnditinal bdy are required. Used fr lps. Parenthesis arund variable are ptinal. Braces arund lp bdy are required. 12

Swift Cntrl Flw Switch 13

Swift Cntrl Flw Switch let can be used in a pattern t assign value N need t break } Only ne match 14

Swift Cntrl Flw fr-in Iterate ver items in a dictinary by prviding a pair f names t use fr each key-value pair. Dictinaries are unrdered! 15

Swift Cntrl Flw While & repeat-while } Same as C r Java s while & d-while. } repeat { } while sme-cnditin Fr lps still the same } Thugh yu can use..< r... t make ranges. 0..<7 nn-inclusive upper bund. fr i in 0..<7 { } 0...7 inclusive upper bund fr i in 0...7 { } 16

Swift Functins & Clsures Use func t declare a functin à t indicate return type Use a tuple t make a cmpund value: return multiple values frm a functin } Elements f a tuple can be referred t by name r by number } Defined as à (min: Int, max: Int, sum: Int) } Access as results.sum, r results.2 17

Swift Functins & Clsures Can take variable arguments, cllects int an array fr yu. Can be nested. 18

Swift Functins & Clsures Functins are first-class types: they can return anther functin as a return-value Can take anther functin as ne f its arguments 19

Swift Functins & Clsures A clsure is a blck f cde that can be called later (annymus functin) Cde in a clsure has access t Variables and functins that were available in the scpe where the clsure was created, even if the clsure is in a different scpe when it is executed Yu can write a clsure withut a name (functin name) } Surrund cde with braces {} } Use in t separate the arguments and return type frm the bdy Syntax: Indicates that definitin f clsure s parameters and return type has finished, and the bdy f the clsure is abut t begin { (parameters) -> return type in } statements 20

Swift Functins & Clsures Cncise 1: if type already knwn, yu can mit types f parameters and/r return type. Cncise 2: can refer t parameters by number instead f name 21

Swift Objects & Classes Classes As we d expect. Use init as initializer / cnstructr. Use deinit as deinitializer / destructr Instantiatin by referencing class name fllwed by () } var shape = Shape() 22

Swift Objects & Classes Classes T inherit, subclasses include their super classes name after their class name, separated by a : } class Square: Shape } class ViewCntrller: UIViewCntrller, UITextFieldDelegate Methds in a subclass that verride the superclass s implementatin are marked with verride } Overriding a methd by accident, withut verride, is detected by the cmpiler as an errr 23

Swift Objects & Classes Prperties can have getter and setter methds. } Similar t Java, C#, VB.Net } Nte newvalue is implicitly defined fr us as the new value (see cde example) } Can be explicit by declaring the setter as: set(<parameter_name>) set( myside ) {... } There is n type declaratin needed because the prperty defined it. 24

Swift Objects & Classes Inheritance } Class: parent } Over ride with verride keywrd. } Call parent methds with super. keywrd. 25

Swift Enumeratins & Structures Enumeratins Use enum t create an enumeratin } Swift assigns raw values starting at zer and increments by 1, but can change this by explicitly specifying values Can have methds assciated with them. 26

Swift Enumeratins & Structures Structures Use struct t create a structure. Supprt many f the same behavirs as classes, including methds & initializers. Structures are passed by value! (classes by reference) 27

Swift Prtcls & Extensins Prtcls It s basically an interface frm ther OO languages. Use prtcl t declare a prtcl. mutating indicates a functin changing the struct. } Nt needed in class redefinitins as class methds can always mdify the class. } Needed in structures t indicate that the methd will mdify the structure. Classes, enumeratins and structs can all adpt prtcls. 28

Swift Prtcls & Extensins Use extensins t add functinality t an existing type 29

Swift Errr Handling Errr Handling Represent errrs using any type that adpts the Errr prtcl. Use thrw t thrw an errr and thrws t dente a functin that can thrw an errr. 30

Swift Errr Handling Errr Handling d / catch } In d blck, mark cde that can thrw an errr by writing try in frnt } In catch blck, the errr is autmatically given the name errr unless yu give it a different name } Can prvide multiple catch blcks that handle specific errrs 31

Swift Cmments 32

Let s Practice! Print strings (use terminatr: t disable \n) let label = "The width is " let width = 94 print(label+string(width)) // cmpare with print(label+string(width), terminatr: ) let apples = 3 let applesummary = "I have \(apples) apples." let ranges = 5 let fruitsummary = "I have \(apples+ranges) pieces f fruit." 33

Let s Practice! Q1: What s wrng with the fllwing cde? Q2: 34

Swift Resurces Cntent was used frm these web sites where apprpriate. These sites cntain quite a bit mre infrmatin and wuld make a great resurce fr yu. https://develper.apple.cm/ https://www.hackingwithswift.cm/read https://www.hackingwithswift.cm/example-cde https://itunes.apple.cm/us/bk/the-swift-prgramminglanguage/id881256329?mt=11 35