Changes

Swift Data Types, Constants and Variables

915 bytes removed, 21:20, 13 April 2015
Type Casting and Type Checking
It is important to note that a value may only be assigned to a constant once. A second attempt to assign a value to a constant will result in a syntax error.
== Type Casting and Type Checking ==
When writing Swift code, situations will occur where the compiler is unable to identify the specific type of a value. This is often the case when a value of ambiguous or unexpected type is returned from a method or function call. In this situation it may be necessary to let the compiler know the type of value that your code is expecting or requires using the as keyword (a concept referred to as type casting). The following code, for example, lets the compiler know that the value returned from the objectForKey method needs to be treated as a String type:
 
<pre>
let myValue = record.objectForKey("comment") as String
</pre>
 
It is also possible to type check a value using the is keyword. The following code, for example, checks that a specific object is an instance of a class named MyClass:
 
<pre>
if myobject is MyClass {
// myobject is an instance of MyClass
}
</pre>
== The Swift Tuple ==