Presentation is loading. Please wait.

Presentation is loading. Please wait.

Make swiftly iOS development Telerik Academy Telerik Academy Plus.

Similar presentations


Presentation on theme: "Make swiftly iOS development Telerik Academy Telerik Academy Plus."— Presentation transcript:

1 Make swiftly iOS development Telerik Academy http://academy.telerik.com Telerik Academy Plus

2  Doncho Minkov  Senior Technical Trainer @ Telerik Software Academy  Contestant in the Informatics competitions  Experience with Web and Mobile apps  Proficient with JavaScript and.NET  Email: doncho.minkov [at] telerik.com  Blog: http://minkov.it http://minkov.it

3  Swift overview  Language syntax and specifics  Variables, structures and optional values  Control structures: if-else, switch, loops  Functions as first-class objects, closures, etc…  OOP: classes, protocols, enums, extensions  Syntactic sugar: destructuring assignments  iOS applications with Swift  Handling gestures on the UI  Using graphics and animations

4 What and Why?

5  Swift is an innovative new programming language for Cocoa and Cocoa Touch  Writing code is interactive and fun  The syntax is concise yet expressive  Apps run lightning-fast  Swift can be used for creating brand-new iOS and OS X apps  Or to add features to applications written with Objective-C

6  Swift was introduced at WWDC 2014 as the "new way to create apps for iPhone and iPad"  Objective-C without the C  Descendant to Objective-C  No pointers  Functions as first-class objects  Influenced from many modern languages:  JavaScript, Objective-C, C#, Python, Scala, etc…

7  Since Swift is pretty new and still needs exploring Apple has provided ways to experiment the new features:  REPL (Read Eval Print Loop)  Run swift code from the Terminal  Xcode interactive Playground  Immediate code evaluation, while typing

8  To use the REPL of Swift follow the steps: 1.Start Terminal.app 2.Type 3.Type code directly inside the Terminal 4.The output is shown directly on the Terminal  You can also execute code from a swift file: $ swift $ swift print-primes.swift

9 Live Demo

10  Apple has provided a Playground for experimenting with Swift features inside Xcode  Write code and receive immediate result  Great for exploring Swift features and research  Allows fast testing of features and syntax

11 Live Demo

12 Laying the groundwork

13  Swift syntax:  Variables and contants  Control structures  If-else, loops, switch  Data structures  Arrays, dictionaries, sets  Classes and structures  Init functions, methods, properties, fields  OOP  Protocols, extensions, inheritance

14 var and let, primitive and reference, functions

15  Swift supports the common data types, coming from Objective-C  Int for creating integers numbers  UInt for creating unsigned integer numbers  Float, Double for floating-point numbers  Bool for Boolean values  [] for array, [Int] for array of integers  Swift supports both structures and classes  Structures create primitive types  Classes create reference types

16  Swift provides two keywords for creating variables:  let and var  var creates a mutable variable  Its value can be changed any time  The type can be provided or inferred  let creates immutable variable  If the type is struct, its value cannot be changed  If the type is object, it can be changed only internally

17  Creating a variable of type integer:  Using let let numberOfCourses: Int = 15 numberOfCourses = 16 // compiler error  Using var var count :Int = 15 count++ //this is Ok  Variable types are inferred  The compiler will understand that you want Int  Works with let and var let numberOfCourses = 15 var count = 15

18 Live Demo

19  Functions in Swift have the following syntax:  Function returning void: func printMessage(message: String) { println(String(format: "Message: %@", message)) println(String(format: "Message: %@", message))}  Function returning integer: func sum(x: Int, y: Int) -> Int { return x + y return x + y}  Function with parameters put inside an array: func sum(numbers: Int…) -> Int { var sum = 0 var sum = 0 for number in numbers { sum += number} for number in numbers { sum += number} return sum return sum}

20 Live Demo

21  Swift supports the standard control flow structures: if condition { //run code //run code} else if condition2 { //run other code //run other code} else { //run third code //run third code} switch language { case "Objective-C", "Swift": println("iOS") println("iOS") case "Java": println("Android") println("Android") case "C#": println("Windows Phone") println("Windows Phone")default: println("Another platform") println("Another platform")} switchif-else

22 Live Demo

23  Swift supports the standard control flow structures:  for loop for i in 0...11 { //i gets the values from 0 to 11, inclusive //i gets the values from 0 to 11, inclusive} for i in 0..<11 { //i gets the values from 0 to 10, inclusive //i gets the values from 0 to 10, inclusive}  while loop while condition { //run code //run code}

24

25  Swift has built-in arrays and dictionaries  let creates immutable dictionary/array  var creates mutable dictionary/array  Immutable arrays: let numbers: [Int] = [1, 2, 3, 4, 5] numbers[2] = -1 //compile error numbers.append(6) //compile error  Mutable arrays: var names: [String] = ["Doncho", "Ivaylo"] names.append("Nikolay") //Doncho, Ivaylo, Nikolay names.append("Pesho") //Doncho, Ivaylo, Nikolay, Pesho names[3] = "Evlogi" //Doncho, Ivaylo, Nikolay, Evlogi  Same for dictionaries

26 Live Demo

27 Introducing the OOP principles in Swift

28  Swift is an OOP language  Has classes, structures and protocols class Square{ var x: Float var x: Float var y: Float var y: Float var side: Float var side: Float init(x: Float, y: Float, side: Float){ init(x: Float, y: Float, side: Float){ self.x = x self.x = x self.y = y self.y = y self.side = side self.side = side } func calcArea() -> Float{ func calcArea() -> Float{ return self.side * self.side return self.side * self.side }}

29 Live Demo

30  Protocols in Swift are pretty much the same as in Objective-C  Almost like interfaces in C# and Java  They provide a public interface for the conforming classes to implement protocol Movable{ func moveToX(x: Int, y: Int) func moveToX(x: Int, y: Int) func moveByDx(dx:Int, dy: Int) func moveByDx(dx:Int, dy: Int)} class Shape: Movable{ func moveToX(x: Int, y: Int){ func moveToX(x: Int, y: Int){ //implementation //implementation } func moveByDx(dx: Int, dy: Int){ func moveByDx(dx: Int, dy: Int){ //implementation //implementation }}

31 Live Demo

32

33  A limited number of animatable properties  Custom animatable properties cannot be created  All animations are disabled by default  Animations are enabled only when using special constructs let view = UIView(frame: CGRectMake(x, y, w, h)) UIView.animateWithDuration( 1.0 animations: { animations: { let frame = CGRectMake(x + 100, let frame = CGRectMake(x + 100, y + 100, y + 100, w, w, h) h) view.frame = frame view.frame = frame});

34 UIView.animateWithDuration( 1.0 delay: 1.0 delay: 1.0 options: UIViewAnimationOptions.CurveEaseIn options: UIViewAnimationOptions.CurveEaseIn animations: { animations: { let frame = CGRectMake(x + 100, let frame = CGRectMake(x + 100, y + 100, y + 100, w, w, h) h) view.frame = frame view.frame = frame}, completion: { completion: { view.alpha = 0.5 view.alpha = 0.5});  UIKit Animations with Animation Blocks

35 Live Demo

36 форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране http://academy.telerik.com


Download ppt "Make swiftly iOS development Telerik Academy Telerik Academy Plus."

Similar presentations


Ads by Google