Download - The Swift Programming Language with iOS App

Transcript
Page 1: The Swift Programming Language with iOS App

IOS 8 Featuresand

Swift DevelopmentPresenter: Vivek Chaudhary, Mindfire SolutionsDate: 08/05/2013

Page 2: The Swift Programming Language with iOS App

IOS 8 Features Swift Development Syntax and Basics Objective C to Swift Sample Code Pros and Cons

Page 3: The Swift Programming Language with iOS App

Battery usage indicator Interactive Notifications Credit Card Scanning New keyboard Continuity Family Sharing

Page 4: The Swift Programming Language with iOS App

Message UI and new widgets Lock screen app suggestions Healthkit Improved search results

Page 5: The Swift Programming Language with iOS App

Some syntax from Java Script Smartly detects data types itself Objective C API + Additional No semicolon Body Braces compulsory for If-else

Page 6: The Swift Programming Language with iOS App

Single file in place of two files (.h and .m) Declaration and implementation in the same

file Reduces the project size Number of files reduces to half

Page 7: The Swift Programming Language with iOS App

1. let someConstant : String = “constant”2. var someVar : String = “variable”

Swift is smart enough to detect data types Var someVar = “variable” Var var1 = 1 Var var2 = 1.0

Page 8: The Swift Programming Language with iOS App

NSString and String both are available1. Let string = “Hello”2. Let anotherString = string + “Mindfire”

1. For char in str2. {3. // Code Here4. }

Page 9: The Swift Programming Language with iOS App

Objective C [NSString stringWithFormat:] Swift \(expression)

Let var1 = 2 Let var2 = 3 Println( “Multiplication is : \(var1 * var2)”)

Page 10: The Swift Programming Language with iOS App

1. let someArray:String[] = [“A”, “B”, “C”]2. let someArray = [“A”, “B”, “C”]3. var someArray:String[] = [“A”, “B”, “C”]4. SomeArray += “D”5. SomeArray += [“D”, “E”]6. print(“First Element :\(someArray[0]) ”)

Page 11: The Swift Programming Language with iOS App

1. let dict:Dictionary<String, String> = [“A”:”1”, “B”:”2”]

2. var dict:Dictionary<String, String> = [“A”:”1”, “B”:”2”]

3. var dict = [“A”:”1”, “B”:”2”]

1. dict[“C”] = “3”2. Dict += [“D”:”4”, “E”:”5”]

Page 12: The Swift Programming Language with iOS App

+ and – are sliced off.

func functionName(var1:String, var2:String)->String

Functions can return more than one parameters too.

These are returned in the form of tuples.

Page 13: The Swift Programming Language with iOS App

Function Definitionfunc functionName(var1:String, var2:String)-

>(String, Int)

Function CallingVar result : (res1:String, res2:Int) =

self.functionName(var1:”Hello”, var2:”Mobile”)Print(“result is \(result.res1)”;

Page 14: The Swift Programming Language with iOS App

Type id changes to AnyObject Downcast is done automatically by swift. “as” keyword is used to typecast

Var textField: UITextField = array.firstObject() as UITextField

Page 15: The Swift Programming Language with iOS App

One has to manually change his Objective C code to Swift

- changes to func + changes to class func #define changes to let #pragma changes to // MARK :

Page 16: The Swift Programming Language with iOS App

init is not used in swift. InitWith and with is also not used. Complex macros should be converted into

functionsLet myColor = UIColor(red:0.5,

green:0.5,blue:0.5, alpha:1.0);

Page 17: The Swift Programming Language with iOS App

PLAYGROUNDS

Page 18: The Swift Programming Language with iOS App
Page 19: The Swift Programming Language with iOS App

REFRENCE LINKS

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/http://code.tutsplus.com/tutorials/an-introduction-to-swift-part-1--cms-21389

Page 20: The Swift Programming Language with iOS App

Presenter: Debasish Mohanty, Mindfire Solutions

Thank you

Page 21: The Swift Programming Language with iOS App

www.mindfiresolutions.com

https://www.facebook.com/MindfireSolutions

http://www.linkedin.com/company/mindfire-solutions

http://twitter.com/mindfires