About Memory:
1. How do I get memory, i.e how are variables declared. Any specific facts and constrains about variables ?
If type annotation like var Varb:Float ; is not used then it is mandatory to assign the initial value to the variable.
"Var" keyword should get you the required memory.
2. How do we get the entry point for the program execution ? [ Example : main() in the C program ]
Script based. There is no particular entry point.
3. How does dynamic memory handled ? Is it supported in first place ?
Instances for the classes can be created. Automatic Reference counting mechanism has the strong reference to one of the variable. Till there is strong reference to the variable it'll be there in the memory. Once there is no strong reference it'll be de-initialized. [ Ref : https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html ]
4. What are the datatypes which are supported and its range?
Yes in form of classes. However you also have the capability to create a new alias for existing data types in form as follows :
6. How do you cast from one data type to other data type ?
[ Reference : https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TypeCasting.html ]
Type casting in Swift is implemented with the
_________________________________________________________________________________
About Program Control :
1. What are the program control options available ? [ like "IF ELSE" , "Switch Case ]
Iterative Statements :
a. For loop
b. While loop
c. Repeat - while loop
Conditional Evaluation Statement :
a. If statement
b. Switch statement
2. How are Boolean operations supported ?
NOT
AND
OR
XOR
Left and Right shift operators
Usual Arithmetic
4. What are the operations supported ?[Arithmetic and special ]
All as those of C
_________________________________________________________________________________
Program refactoring :
1. How do you subprogram ?
2. What are argument passing paradigms supported for subprograms ?
a. Pass by value as in the above example for function. Or
b. By reference using "inout" keyword.
3. What are the ways in which multi threading applications are created in the programs ?
Delayed Asnyc Execution :
let delay = DispatchTime.now() + .seconds(60) DispatchQueue.main.asyncAfter(deadline: delay) { // Dodge this! }
Que based dispatching :
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { // Download file or perform expensive task dispatch_async(dispatch_get_main_queue()) { // Update the UI } }
Normal function calls
_________________________________________________________________________________
Special Operations :
1. Have the overview of string,file,system operations supported by the language's standard library.
[ Reference to string library of Swift : https://developer.apple.com/documentation/swift/string }
2. How exceptions are handled and common exceptions.
3. What is the function recursion depth supported.
Test it out your self. :)
4. Some language specific concepts : Like class hierarchy(if OO), creating disposable objects, function injection, detecting for loop abrupt breaks etc ..
Coming soon ...
1. How do I get memory, i.e how are variables declared. Any specific facts and constrains about variables ?
If type annotation like var Varb:Float ; is not used then it is mandatory to assign the initial value to the variable.
"Var" keyword should get you the required memory.
2. How do we get the entry point for the program execution ? [ Example : main() in the C program ]
Script based. There is no particular entry point.
3. How does dynamic memory handled ? Is it supported in first place ?
Instances for the classes can be created. Automatic Reference counting mechanism has the strong reference to one of the variable. Till there is strong reference to the variable it'll be there in the memory. Once there is no strong reference it'll be de-initialized. [ Ref : https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html ]
4. What are the datatypes which are supported and its range?
- Int or UInt − This is used for whole numbers. More specifically, you can use Int32, Int64 to define 32 or 64 bit signed integer, whereas UInt32 or UInt64 to define 32 or 64 bit unsigned integer variables. For example, 42 and -23.
- Float − This is used to represent a 32-bit floating-point number and numbers with smaller decimal points. For example, 3.14159, 0.1, and -273.158.
- Double − This is used to represent a 64-bit floating-point number and used when floating-point values must be very large. For example, 3.14159, 0.1, and -273.158.
- Bool − This represents a Boolean value which is either true or false.
- String − This is an ordered collection of characters. For example, "Hello, World!"
- Character − This is a single-character string literal. For example, "C"
- Optional − This represents a variable that can hold either a value or no value.
We have listed here a few important points related to Integer types −
- On a 32-bit platform, Int is the same size as Int32.
- On a 64-bit platform, Int is the same size as Int64.
- On a 32-bit platform, UInt is the same size as UInt32.
- On a 64-bit platform, UInt is the same size as UInt64.
- Int8, Int16, Int32, Int64 can be used to represent 8 Bit, 16 Bit, 32 Bit, and 64 Bit forms of signed integer.
- UInt8, UInt16, UInt32, and UInt64 can be used to represent 8 Bit, 16 Bit, 32 Bit and 64 Bit forms of unsigned integer.
Yes in form of classes. However you also have the capability to create a new alias for existing data types in form as follows :
import Cocoa typealias Feet = Int var distance: Feet = 100 println(distance)
[ Reference : https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TypeCasting.html ]
Type casting in Swift is implemented with the
is
and as
operators. These two operators provide a simple and expressive way to check the type of a value or cast a value to a different type._________________________________________________________________________________
About Program Control :
1. What are the program control options available ? [ like "IF ELSE" , "Switch Case ]
Iterative Statements :
a. For loop
b. While loop
c. Repeat - while loop
repeat {
statements
} while condition
a. If statement
b. Switch statement
switch some value to consider {
case value 1:
respond to value 1
case value 2,
value 3:
respond to value 2 or 3
default:
otherwise, do something else
}
2. How are Boolean operations supported ?
Swift supports all standard C comparison operators:
- Equal to (
a == b
) - Not equal to (
a != b
) - Greater than (
a > b
) - Less than (
a < b
) - Greater than or equal to (
a >= b
) - Less than or equal to (
a <= b
)
NOT
AND
OR
XOR
Left and Right shift operators
Usual Arithmetic
4. What are the operations supported ?[Arithmetic and special ]
All as those of C
_________________________________________________________________________________
Program refactoring :
1. How do you subprogram ?
The function in the example below is called
greet(person:)
, because that’s what it does—it takes a person’s name as input and returns a greeting for that person. To accomplish this, you define one input parameter—a String
value called person
—and a return type of String
, which will contain a greeting for that person:func greet(person: String) -> String {
let greeting = "Hello, " + person + "!"
return greeting
}
a. Pass by value as in the above example for function. Or
b. By reference using "inout" keyword.
Here’s an example of a function called
swapTwoInts(_:_:)
, which has two in-out integer parameters called a
and b
:func swapTwoInts(_ a: inout Int, _ b: inout Int) {
let temporaryA = a
a = b
b = temporaryA
}
Delayed Asnyc Execution :
let delay = DispatchTime.now() + .seconds(60) DispatchQueue.main.asyncAfter(deadline: delay) { // Dodge this! }
Que based dispatching :
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { // Download file or perform expensive task dispatch_async(dispatch_get_main_queue()) { // Update the UI } }
var note:Object
note.saveInBackground {
var alert = "Your note has been saved!"
alert.show()
}
In the pseudo-code example above we’re creating a
note
object, which is saved in the background. When it has been saved the completion handler (a closure) is executed, showing an alert dialog to the user.
The
4. How are subprograms called , what are the options we have got ?saveInBackground()
method will use some form of concurrency. The Cocoa Touch SDK has several options for concurrency, of which Grand Central Dispatch (GCD) is the most common.Normal function calls
_________________________________________________________________________________
Special Operations :
1. Have the overview of string,file,system operations supported by the language's standard library.
[ Reference to string library of Swift : https://developer.apple.com/documentation/swift/string }
2. How exceptions are handled and common exceptions.
To indicate that a function, method, or initializer can throw an error, you write the
throws
keyword in the function’s declaration after its parameters. A function marked with throws
is called a throwing function. If the function specifies a return type, you write the throws
keyword before the return arrow (->
).func canThrowErrors() throws -> String
func cannotThrowErrors() -> String
Handling Errors Using Do-Catch
You use a
do
-catch
statement to handle errors by running a block of code. If an error is thrown by the code in the do
clause, it is matched against the catch
clauses to determine which one of them can handle the error.
Here is the general form of a
do
-catch
statement:do {
try expression
statements
} catch pattern 1 {
statements
} catch pattern 2 where condition {
statements
}
Test it out your self. :)
4. Some language specific concepts : Like class hierarchy(if OO), creating disposable objects, function injection, detecting for loop abrupt breaks etc ..
Coming soon ...
Comments
Post a Comment