the swift programming language with ios app

Post on 06-May-2015

1.403 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Swift is the latest new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. This presentation is all about swift programming along with major iOS 8 Features and changes.

TRANSCRIPT

IOS 8 Featuresand

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

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

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

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

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

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

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

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

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

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

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

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]) ”)

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”]

+ 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.

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)”;

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

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

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 :

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);

PLAYGROUNDS

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

Presenter: Debasish Mohanty, Mindfire Solutions

Thank you

www.mindfiresolutions.com

https://www.facebook.com/MindfireSolutions

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

http://twitter.com/mindfires

top related