CSC/ECE 517 Fall 2014/ch1a 13 va: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 24: Line 24:
The latest Xcode version 6 includes Playgrounds which has an interactive sidebar to display the results of the code on-the-fly.
The latest Xcode version 6 includes Playgrounds which has an interactive sidebar to display the results of the code on-the-fly.


==Swift==
===Swift===
Swift<ref>http://en.wikipedia.org/wiki/Swift_(programming_language)</ref> is a new programming language that adopts safe programming patterns and makes programming flexible. Swift combines the best of both C and Objective-C. It integrates both - the procedural features like types and operators as well as the object-oriented features such as classes and protocols.  It adopts readability and dynamic object model from Objective-C and has added new features like blocks, collection literals and modules, fast performance. Swift has many advantages over Objective-C, like being more type-safe, having more natural and concise syntax, no need for header/implementation files. It simplified memory management with Automatic Reference Counting<ref>http://en.wikipedia.org/wiki/Automatic_Reference_Counting</ref>. Swift is a fast and powerful programming language that is easier and more fun to implement.
Swift<ref>http://en.wikipedia.org/wiki/Swift_(programming_language)</ref> is a new programming language that adopts safe programming patterns and makes programming flexible. Swift combines the best of both C and Objective-C. It integrates both - the procedural features like types and operators as well as the object-oriented features such as classes and protocols.  It adopts readability and dynamic object model from Objective-C and has added new features like blocks, collection literals and modules, fast performance. Swift has many advantages over Objective-C, like being more type-safe, having more natural and concise syntax, no need for header/implementation files. It simplified memory management with Automatic Reference Counting<ref>http://en.wikipedia.org/wiki/Automatic_Reference_Counting</ref>. Swift is a fast and powerful programming language that is easier and more fun to implement.



Revision as of 22:35, 19 September 2014

Fig 1: Playgrounds with Swift in Xcode v6.0
Fig 1: Playgrounds with Swift in Xcode v6.0


Playgrounds with Swift in XCode v6.0

On June 2, 2014 at the World Wide Developers Conference, Apple announced version 6 of Xcode. Features include "Playgrounds," live debugging tools, as well as an entirely new programming language called Swift. A key element of the Swift system is its ability to be cleanly debugged and run within the development environment, using a read–eval–print loop (REPL), giving it interactive properties more in common with scripting systems like Python than traditional systems programming languages. The REPL is further enhanced with the new 'playgrounds' concept; 'playgrounds' are interactive views running within the Xcode environment that respond to code or debugger changes on-the-fly. If the code in question changes over time or with regard to some other ranged input value, the view can be used with the Timeline Assistant to demonstrate the output in an animated fashion.

Apple claims that Swift "is the first industrial-quality systems programming language that is as expressive and enjoyable as a scripting language."

Topic Document

Background

XCode

Xcode<ref>http://en.wikipedia.org/wiki/Xcode</ref> is an Integration Development Environment (IDE) developed by Apple for developing software for iOS and OS X. The Xcode suite consists of the IDE, Apple’s developer documentation and a built-in interface builder. It is shipped free with Mac OS X 10.3, but is able to develop OS X applications that can run on any version of OS X. It extends and replaces Apple's earlier tool, Project Builder, which was inherited from NeXT. However, Xcode officially does not work in Mac OS X 10.2.It works hand in hand with Interface Builder (also inherited from NeXT), a graphical tool used to create user interfaces.

Xcode includes GCC, and can compile C, C++, Objective C++, Java, and Objective C source code with a variety of programming models, including but not limited to Cocoa, Carbon, and Java. The latest Xcode version 6 includes Playgrounds which has an interactive sidebar to display the results of the code on-the-fly.

Swift

Swift<ref>http://en.wikipedia.org/wiki/Swift_(programming_language)</ref> is a new programming language that adopts safe programming patterns and makes programming flexible. Swift combines the best of both C and Objective-C. It integrates both - the procedural features like types and operators as well as the object-oriented features such as classes and protocols. It adopts readability and dynamic object model from Objective-C and has added new features like blocks, collection literals and modules, fast performance. Swift has many advantages over Objective-C, like being more type-safe, having more natural and concise syntax, no need for header/implementation files. It simplified memory management with Automatic Reference Counting<ref>http://en.wikipedia.org/wiki/Automatic_Reference_Counting</ref>. Swift is a fast and powerful programming language that is easier and more fun to implement.

Playgrounds

Playgrounds enable the interactive experience of a script language, even though Swift compiles to highly-optimized native code. Type a line of code and the result appears immediately. IIf your code runs over time, for instance through a loop, you can watch its progress in the Timeline assistant. The Timeline displays variables in a graph, draws each step when composing a view, and can play an animated SpriteKit scene.

Getting familiar with Playground

Playground files are used for testing and prototyping code. The results in the sidebar are displayed in black but if you modify your code, the results temporarily change to gray during processing.

More About Playground

You can also draw shapes and see them on the playground:

You can use ImageView:

You can also see the value of iterator in a loop by viewing the timeline:

Changing the value of shift here, you will get a new graph:

Viewing Result

To view graphical display of results, like images or strings, you can click on the Quick Look (quicklook.png ) button. Access to Quick Look buttons can be gained by moving the pointer along the right edge of the sidebar.

Assistant Editor button can be used to examine values that change throughout the execution of the code.
i. Interim value of a code like for loop can be viewed through Value History button ()
ii. Live view item can be used to view the drawing results. Live view item draws itself in response to the code.


Timeline

You can view the progress of results on the timeline. You can also set the time limit for the timeline to play back values. An item can be collapsed or expanded by clicking on the expression at the top of the item. An item can be removed from the timeline by clicking on the close button on the upper left corner of the item. You can close the timeline by clicking on the close button on the Assistant Editor jump bar. It can be opened by clicking on the Assistant Editor button in the workspace toolbar or by clicking any Value History button.

Error

An error symbol is displayed to mark an error. The explanation of the error can be seen by clicking on the error symbol.

Hello Playground Example

You do not need import statements in Swift.

We do not need to create a class, main file etc: If we write str in Swift, the result will be displayed on Playground.

You do not need semicolons at the end of the line. You do not need to explicitly state the data type, but you can do it if you want as shown in the screen below:

You will get an error if you explicitly state the value of a variable and then assign it some different value. The error message is shown as a ! icon:

Swift also uses a keyword “let” for declaring constants. If you change the value of a constant declared with “let”, you will get an error:

You can also iterate through the loop and the value of iterator can be shown on the console on-the-fly:

Read-Eval-Print-Loop (REPL)

Recent Updates

On September 9th 2014, Apple published in their developer's blog that 'Swift Has Reached 1.0'

See Also

http://apple.wikia.com/wiki/Xcode


References

<references/>