Swift. Introduced in 2014 Replaces Objective-C as “recommended development language” “safer, succinct, readable” Emphasizes type safety.

Slides:



Advertisements
Similar presentations
Slide: 1 Copyright © AdaCore Arrays Presented Quentin Ochem university.adacore.com.
Advertisements

CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
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.
Constants and Data Types Constants Data Types Reading for this class: L&L,
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Introduction to ML - Part 2 Kenny Zhu. What is next? ML has a rich set of structured values Tuples: (17, true, “stuff”) Records: {name = “george”, age.
CS102 Data Types in Java CS 102 Java’s Central Casting.
Arrays Hanly - Chapter 7 Friedman-Koffman - Chapter 9.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.
String Escape Sequences
JavaServer Pages Syntax Harry Richard Erwin, PhD CSE301/CIT304.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
CIS Computer Programming Logic
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
C Programming Tutorial – Part I CS Introduction to Operating Systems.
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
Chapter 8: Arrays.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Arrays BCIS 3680 Enterprise Programming. Overview 2  Array terminology  Creating arrays  Declaring and instantiating an array  Assigning value to.
410/510 1 of 18 Week 5 – Lecture 1 Semantic Analysis Compiler Construction.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
Lecture 131 CS110 Lecture 13 Thursday, March 11, 2004 Announcements –hw5 due tonight –Spring break next week –hw6 due two weeks from tonight Agenda –questions.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
CompSci Arrays  Aggregate data type  Deal with items of same type  Lists of words  Numbers  Analogies  Mailboxes in post office  CD racks.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
ICAPRG301A Week 2 Strings and things Charles Babbage Developed the design for the first computer which he called a difference engine, though.
Introduction to Java Java Translation Program Structure
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,
Data Types Declarations Expressions Data storage C++ Basics.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Copyright Curt Hill The C/C++ switch Statement A multi-path decision statement.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
“Great leaders are never satisfied with current levels of performance. They are restlessly driven by possibilities and potential achievements.” – Donna.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
Fundamental Programming Fundamental Programming More Expressions and Data Types.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Asserting Java © Rick Mercer Chapter 7 The Java Array Object.
© Rick Mercer Chapter 7 The Java Array Object.  Some variables store precisely one value: a double stores one floating-point number a double stores one.
Sequences and for loops. Simple for loops A for loop is used to do something with every element of a sequence scala> for (i
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
Types CSCE 314 Spring 2016.
Haskell Chapter 2.
Programming for Mobile Technologies
Java for Android is specific
Multiple variables can be created in one declaration
JSON Crash Course Traversy Media.
Thinking about programming
CHAPTER THREE Sequences.
Variables Numbers can be stored and retrieved while a program is running if they are given a home. The way that integers and decimal numbers are stored.
Introduction to Primitive Data types
C++ Data Types Data Type
Sridhar Narayan Java Basics Sridhar Narayan
Chapter 7 The Java Array Object © Rick Mercer.
Thinking about programming
Java’s Central Casting
Chap 2. Identifiers, Keywords, and Types
CSC 581: Mobile App Development
Introduction to Primitive Data types
Presentation transcript:

Swift

Introduced in 2014 Replaces Objective-C as “recommended development language” “safer, succinct, readable” Emphasizes type safety

Resources iOS Programming: The Big Nerd Ranch Guide Swift Programming: The Big Nerd Ranch Guide The Swift Programming Language (Apple )

Types Structures, classes, enumerations All three can have properties, initializers, instance methods, class or static methods Types that are often primitive types are structures: – Numbers: Int, Float, Double – Boolean: Bool – Text: String, Character – Collections: Array, Dictionary, Set Optionals: value of a particular type or no value

Playgrounds Xcode: File  New  Playground… Type in code on the left Results show up in the sidebar on the right Watch out for errors. No results will show up after an error.

Variables and constants var var str = “I can change my value” let let constStr = “I can’t change my value” Notice there are no declared types. Swift does type inference based on initial values. Is that a good thing?

Numbers and boolean values Integers: Various types, but usually use Int var nextYear: Int Floating point: Float (32-bit), Double (64-bit), Float80 (80-bit) var bodyTemp: Float Boolean: Bool, has values true or false var hasPet: Bool

Arrays Ordered collection of elements Type is Array where T is the type of the elements All elements must be the same type var arrayOfInts: Array var arrayOfInts2: [Int] var arrayOfInts3 = [1, 2, 3]

Dictionaries Unordered collection of key-value pairs Values can be any type Keys must be hashable – Int, Float, Character, String are all hashable Can only contain keys and values of declared types var capitals: Dictionary var capitals: [String: String] var capitals = [“Germany”: “Berlin”, “Japan”: “Tokyo”, “UK”: “London”]

Sets Similar to an array but members must be unique and are unordered var lotteryNumbers: Set

Literals String literals: double quotes “All your base are belong to us” Number literals: 42, 91.1 Array literals: square brackets [“one”, “two”, “three”] Dictionary literals: square brackets with colons

Fun! with optionals? var y: Float // nil value might crash program var x: Float? // proper unwrapping prevents crashes y = x // compiler error y = x! // Don’t use the force, Luke! if let y = x { // handle non-nil case } else { // handle nil case }

Optionals aren’t optional Even if you never declare variables as optional, you will still have to deal with optionals. Subscripting a dictionary returns an optional.

for loops a = [1, 2, 3] for var i = 0; i < a.count; ++i { print(i); } for i in [1, 2, 3] { print(i) } Can use range, enumerate