Showing posts with label Swift. Show all posts
Showing posts with label Swift. Show all posts

Monday, 23 March 2015

HB Blog 64: REPL (Read-Eval-Print-Loop) Environment In iOS Playground File.

A read–eval–print loop (REPL), also known as an interactive toplevel or language shell, is a simple, interactive computer programming environment that takes single user inputs (i.e. single expressions), evaluates them, and returns the result to the user; a program written in a REPL environment is executed piecewise.
In a REPL, the user enters one or more expressions (rather than an entire compilation unit) and the REPL evaluates them and display the results.
    The read function accepts an expression from the user, and parses it into a data structure in memory. For instance, the user may enter the s-expression (+ 1 2 3), which is parsed into a linked list containing four data elements.
    The eval function takes this internal data structure and evaluates it. In Lisp, evaluating an s-expression beginning with the name of a function means calling that function on the arguments that make up the rest of the expression. So the function + is called on the arguments 1 2 3, yielding the result 6.
    The print function takes the result yielded by eval, and prints it out to the user. If it is a complex expression, it may be pretty-printed to make it easier to understand. In this example, though, the number 6 does not need much formatting to print.

Most recent example is Playground file. Without requiring you to compile and run a complete project, a playground provides quick feedback for the results of your coding experiments. You just need to select a .playground file in the project navigator in xcode, or create a .playground file by choosing File > New > File and selecting the Playground source template for your ios platform. Enter the code into the .playground file, and examine the results in the sidebar. The quick look option opens assistant editor which will open with a timeline view, containing a graph of these values over time.

Below  is the exapmle for fibonacci series in playground in swift language on iOS platform.

Saturday, 24 January 2015

HB Blog 54: Objective-C And(not VS) Swift.

I have been thinking a lot about the right tile for this post. Objective-C And(not VS) Swift sounds more
informative rather than comparison and differences. Afterall, we don't prefer to discriminate on basic of
languages.

Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. It is the main programming language used by Apple for the OS X and iOS operating systems, and their respective application programming interfaces (APIs), Cocoa and Cocoa Touch.

Swift is a multi-paradigm, compiled programming language created by Apple for iOS and OS X development. Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks and the large body of existing Objective-C code written for Apple products.

There many similarity between both of them as follows:-
1)Both are used by Apple.(I need not brief on that context.)
2)Both have same basic numeric types (Int, UInt, Float, Double).
3)Both use curly braces to group statements.
4)In both, variables are assigned using an equals sign, but compared using two consecutive equals signs.
5)In both, control statements, for, while, if, switch are similar.
6)In both, class methods are inherited, just like instance methods, self in class methods is the class the method was called on.

But,they both have few differences too,
1)In Swift, statements do not need to end with a semicolon (;), though they must be used to allow more than one statement on a line
2)In Swift, header files are not required
3)In Swift, functions are first-class objects.
4)In Swift, enumeration cases can have associated data (algebraic data types).
5)In Swift, operators can be redefined for classes (operator overloading), and new operators can be created.
6)In Swift, strings fully support Unicode. Most Unicode characters can be used in either identifiers or operators.
7)In Swift, no exception handling (though it can be emulated through use of closures).
This is not seen in Objective-C.