Swift 2021 _ Tutorialpoint Flashcards
Define Swift 4?
Apple programming Language - designed for iOS and OSX development
Most recent API compatible?
iOS 6
OSX 10.8
Using Swift, is actually fantastic at?
Developing iOS and OSX developments
Using Swift, provides seamless access?
Existing Cocoa frameworks
Using Swift, unifies what?
Procedural and Object-oriented parts of the lanuage
Is a separate library required for certain functionalities?
NOPE!
Swift 4 comes with X that helps programmers to write and execute code?
Playground!
Getting Started
- install XCode
- open it
- select ‘Get started with a playground’
Swift ‘Hello World’ - Playgound
import UIKit var str = "Hello, playground"
Swift ‘Hello World’ - OSX
import Cocoa var str = "Hello, playground"
‘Hello World’s difference??
import UIKit
VS
import Cocoa
Semicolon - single line - required?
Nope
but optional
Semicolon - for multi lined?
Required!
Special Characters not allowed as Identifiers?
@, $, %
Is Swift case sensitive?
YEs
How to use a reserved word as an identifier?
class
Use ( ` ) - backtick
Whitespaces?
Totally ignored!
Type of Whitespaces?
blanks, tabs, newline characters, AND comments
Correct use of spacing?
int fruit = apples +oranges //is a wrong statement
int fruit = apples + oranges //is a Correct statement
Printing in Swift
3 properties:
- Items
- Separator
- Terminator
print(‘hello world”)
Type Aliases
typealias newname = type
eg
typealias Feet = Int
Type Safety means?
if part of your code expects a String you cannot pass it an ‘int’ by mistake
Cannot assign error?
main.swift:2:8: error: cannot assign value of type ‘String’ to type ‘Int’
varA = “This is hello”
Type Annotations are spelled out:
var variableName: =
Eg of Printing Variables
var varA = "Godzilla" var varB = 1000.00
print(“Value of (varA) is more than (varB) millions”)
What’s special about Optional types?
They are a type on their own.
Values of Optionals?
-None
-Some(T)
T - is an associated value of the data type available
Optional - types
To make values ‘nil’
Tuples are?
Used to group multiple values in a single compound Value
Tuple types
Can be any type
Tuple example
var TupleName = (Value1, value2,… any number of values)
Tuple declaration
var error501 = (501, “Not implemented”)
Tuple reference index(es)
print(“The code is(error501.0)”)
print(“The definition of error is(error501.1)”)
What kind of data type can be made constant?
Any and all
Logical Operators
&&( A && B)
|| (A || B)
! (A&&B)
Ternary
Exp1 ? Exp2 : Exp3;
Finding String length?
var varA = “Hello, Swift 4!”
print( “(varA), length is ((varA.count))” )
How to iterate over string using loops?
for chars in “ThisString” {
print(chars, terminator: “ “)
}
output: T h i s S t r i n g
String: isEmpty( )
A Boolean value that determines whether a string is empty or not.
String: hasPrefix(prefix: String)
Function to check whether a given parameter string exists as a prefix of the string or not.
String:hasSuffix(suffix: String)
Function to check whether a given parameter string exists as a suffix of the string or not.
String: toInt()
Function to convert numeric String value into Integer.
String: count()
Global function to count the number of Characters in a string.
String: utf8
Property return a UTF-8 representation of a string.
String: utf16
Property to return a UTF-16 representation of a string.
String: unicodeScalars
Property to return a Unicode Scalar representation of a string.
String: +
Operator to concatenate two strings, or a string and a character, or two characters.
String: +=
Operator to append a string or character to an existing string.
String: ++
Operator to append a string or character to an existing string.
String: ==
Operator to determine the equality of two strings.
String:
Operator to perform a lexicographical comparison to determine whether one string evaluates as less than another.