Sunday, September 13, 2015

IOS Swift Programming


Swift is a new programming language developed by Apple Inc for iOS and OS X development. Swift adopts the best of C and Objective-C, without the constraints of C compatibility.
Swift uses the same runtime as the existing Obj-C system on Mac OS and iOS which makes Swift programs run on many existing iOS 6 and OS X 10.8 platforms.

Swift is a new programming language developed by Apple Inc for iOS and OS X development. Swift adopts the best of C and Objective-C, without the constraints of C compatibility.
  • Swift makes use of safe programming patterns.
  • Swift provides modern programming features.
  • Swift provides Objective-C like syntax.
  • Swift is a fantastic way to write iOS and OS X apps.
  • Swift provides seamless access to existing Cocoa frameworks.
  • Swift unifies the procedural and object-oriented portions of the language.
  • Swift does not need a separate library import for functionality like input/output or string handling.
Swift uses the same runtime as the existing Obj-C system on Mac OS and iOS which makes Swift programs run on many existing iOS 6 and OS X 10.8 platforms.
Swift comes with playground feature where Swift programmers can write their code and execute it to see the results immediately.
It took almost 14 years to bring the first public release of the Swift language starting from 2010 by Chris Lattner and later supported by many other contributors. and later a great collaboration of many other programmers. Swift has been included in Xcode 6 beta.
Swift designers took ideas from various other popular languages like Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list.


Import in Swift

You can use import statement to import any Objective-C framework (or C library) directly into Swift program. For example above import cocoastatement makes all Cocoa libraries, APIs, and runtimes that form the development layer for all of OS X, available in Swift.
Cocoa is implemented in Objective-C, which is a superset of C, so it is easy to mix C and even C++ into your Swift applications.


Comments

Comments are like helping text in your Swift program and they are ignored by the compiler. Multi line comment starts with /* and terminates with the characters */ as shown below:
/* My first program in Swift */
Multi-line comments can be nested in Swift. Following is a valid comment in Swift:
/* My first program in Swift is Hello, World!
/* Where as second program is Hello, Swift! */
Single comment is written using // in the beginning of the comment.
// My first program in Swift

Semicolons

Swift does not require you to write a semicolon (;) after each statement in your code, though its optional and if you use a semicolon then compiler does not complain about it.
But, if you are using multiple statements in the same line then its required to use a semicolon as a delimiter, otherwise compiler will raise syntax error. You can write above Hello, World! program 
Identifiers
A Swift identifier is a name used to identify a variable, function, or any other user-defined item. An identifier starts with a letter A to Z or a to z or an underscore _ followed by zero or more letters, underscores, and digits (0 to 9).
Swift does not allow punctuation characters such as @, $, and % within identifiers. Swift is a case sensitive programming language. Thus Manpower and manpower are two different identifiers in Swift. Here are some examples of acceptable identifiers:
Azad       zara    abc   move_name  a_123
myname50   _temp   j     a23b9      retVal
To use a reserved word as an identifier, you will need to put a backtick (`) before and after it. For example, class is not a valid identifier, but `class` is valid.



No comments:

Post a Comment

Dharamart.blogspot.in