CSC 581: Mobile App Development

Slides:



Advertisements
Similar presentations
Local Variables and Scope Benjamin Fein. Variable Scope A variable’s scope consists of all code blocks in which it is visible. A variable is considered.
Advertisements

Xcode testing Using XCTest.
Java Programming Constructs 1 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
Introduction to Objective-C and Xcode (Part 3) FA 175 Intro to Mobile App Development.
COP-3330: Object Oriented Programming Flow Control May 16, 2012 Eng. Hector M Lugo-Cordero, MS.
CSC1030 HANDS-ON INTRODUCTION TO JAVA Introductory Lab.
JavaScript scope and closures
1 SWIFT 2.0: New features Dzianis Astravukh AUGUST 5, 2015.
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
Swift. Introduced in 2014 Replaces Objective-C as “recommended development language” “safer, succinct, readable” Emphasizes type safety.
Inside Class Methods Chapter 4. 4 What are variables? Variables store values within methods and may change value as the method processes data.
Chapter 9 A Second Look at Classes and Objects - 4.
Lecture 1 - Intro to Swift
Haskell Chapter 7.
COP 2800 Lake Sumter State College Mark Wilson, Instructor
Basic Introduction to C#
Chapter 3 Control Statements
SETS AND VENN DIAGRAMS.
CMSC 202 Lesson 2 C++ Primer.
A bit of C programming Lecture 3 Uli Raich.
Ruby and other languages….
CHAPTER 4 Selection CSEG1003 Introduction to Computing
Introduction to programming in java
Programming for Mobile Technologies
សាកលវិទ្យាល័យជាតិគ្រប់គ្រង National University of Management
Variables, Printing and if-statements
Chapter 6: Conditional Statements and Loops
Enumerated DATA Types Enum Types Enumerated Data Types
The C “switch” Statement
CS 106A, Lecture 7 Parameters and Return
DAYS OF THE WEEK.
Lesson 2: Building Blocks of Programming
The C “switch” Statement
Time management School of Rock.
CMPE 152: Compiler Design September 18 Class Meeting
Calendar of 2012 ESL Lesson on Months.
A Class Calendar in PowerPoint
JANUARY 2018 SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY
Sunday Monday Tuesday Wednesday Sunday Monday Tuesday Wednesday
Enumerations CS Fall 1999 Enumerations.
Classes, Encapsulation, Methods and Constructors (Continued)
The switch Statement Topics Multiple Selection switch Statement
The switch Statement Topics Multiple Selection switch Statement
Compound Statements A Quick Overview
Enumerated DATA Types Enum Types Enumerated Data Types
CSC 581: Mobile App Development
Java Programming Review 1
The Java switch Statement
CS 240 – Lecture 7 Boolean Operations, Increment and Decrement Operators, Constant Types, enum Types, Precedence.
JANUARY 2018 SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY
Unit 3 Year 2 – Part B Lesson 1 - Practice.
| January Sunday Monday Tuesday Wednesday Thursday Friday
Arrays type Int_Buffer is array (1..10) of Integer;
Arrays.
Standard Version of Starting Out with C++, 4th Edition
CMPE 152: Compiler Design February 21 Class Meeting
Contact
Chapter 3: Selection Structures: Making Decisions
The switch Statement Topics Multiple Selection switch Statement
CSC 581: Mobile App Development
2011年 5月 2011年 6月 2011年 7月 2011年 8月 Sunday Monday Tuesday Wednesday
EECE.2160 ECE Application Programming
CSC 581: Mobile App Development
Corresponds with Chapter 5

BOOKINGS – Monday, 2nd July BAYWAVE
Mr. Butler 6th Grade Earth Science
January Monday Tuesday Wednesday Thursday Friday Saturday Sunday 30 31
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Interfaces, Enumerations, Boxing, and Unboxing
Presentation transcript:

CSC 581: Mobile App Development Spring 2018 Unit 3: Optionals & segues Swift optionals, guards scope, enumerations UIKit segues navigation controllers

Optionals recall: Swift uses optionals when a value may or may not be present var ages = ["Pat": 18, "Chris": 20, "Kelly": 19] print(ages["Chris"])  Optional(20) outputLabel.text = "Hello world" print(outputLabel.text)  Optional("Hello world") you can unwrap an optional using ! or (more elegantly) if-let print(ages["Chris"]!)  20 if let msg = outputLabel.text { print(msg)  Hello world } every type in Swift has a corresponding optional type (with ? at end) var age: Integer? = ages["Chris"] var msg: String? = outputLabel.text

Intentional optionals structs/classes can have optional fields; functions can return optionals struct Profile { var name: String var age: Int? var favoriteMovie: String? func getAge() -> Int? { return age } var person = Profile(name: "Sean", age: 22, favoriteMovie: "Life of Pi") if let age = person.getAge() {     print("\(person.name) is \(age) years old.") else {     print("\(person.name)'s age is unknown") person = Profile(name: "Dave", age: nil, favoriteMovie: "Big Trouble in Little China")

Guards when defining functions, will often have an initial validity test or tests func average(_ nums: [Double]) -> Double { if nums.count > 0 { var sum = 0.0 for n in nums { sum += n } return sum/nums.count else { return 0.0 func display(for person: Profile) {     if let age = person.age {         if let fav = person.favoriteMovie {             print("\(person.name) (age \(age)) loves \(fav)")         }     }

Guards a guard is a cleaner notation for handling validity tests guard condition else { } func average(_ nums: [Double]) -> Double { guard nums.count > 0 else { return 0.0 } var sum = 0.0 for n in nums { sum += n } return sum/nums.count func display(for person: Profile) {     guard let age = person.age, let fav = person.favoriteMovie else { return }             print("\(person.name) (age \(age)) loves \(fav)")

Variable scope as in most languages, a block (code enclosed in { } ) defines a new scope for variables note: a function defines a new scope as well as control statements var x = 100 if true { var y = 3 print("\(x) \(y)")  100 3 } print(x)  100 print(y)  ERROR: Use of unresolved identifier 'y' variable shadowing unlike Java, you can override an existing variable inside a new scope var x = 100 if true { var x = 3 print(x)  3 } print(x)  100

Enumerations as in Java, you can define a new type by enumerating all of the possible values of that type useful when you want a limited range of values to be assignable enum Answer { case yes, no, maybe } enum DayOfWeek { case Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday var response = Answer.yes if (response == .yes || response == .no) { // Swift infers the print("That's a decisive answer") // enum type var today = DayOfWeek.Tuesday print(today)

Segues a view controller manages a screen within an app if an app is to have multiple screens need a view controller for each screen need to define how to transition from one view controller to another a segue defines a transition between view controllers segues are defined in Interface Builder by connecting the controllers can select the presentation method for the transition navigation controllers allow you to go back or jump to other screens complete Lesson 3.6 create an app with multiple views, define segues between them final version has two destination buttons, an enable/disable switch HW3a: complete the lab at the end of 3.6 create an app with a login screen