Swift Test Upwork

Which keyword is used in Swift when we want a property of a class to initialize when it is accessed for the first time?

let

var

const

lazy

Which is used for down casting?

as!

is

is?

as?

The following attribute can be used to allow a protocol to contain optional functions and to be used in ObjC?

objective_bridge

ObjC

_objc

@objc

Which of the following types can be used use as raw value types for an enumeration?

Bool

Array

Int, String, Float

Dictionary

Which keyword do you use to declare enumeration?

var

enum

struct

case

When declaring an enumeration, multiple member values can appear on a single line, separated by which punctuation mark?

Semi-colon

Colon

Comma

Slash

Point

In Swift, objects are usually references to instances for both _____ and classes?

composite

structures

interface

compound

What is wrong with the following code?

import UIKit

var intVar:Int?=3

intVar = nil

var strVar:String

strVar = nil

var intVar decalaration is incorrect

strVar cannot be initialized with nil

intVar cannot be initialized with nil

everything is ok

How do you get a local IP address in Swift?

GetAdapterInfo

getnameinfo

socket

getIP() 440

Which superclass is the following code?

class X: Y {

let str:String

let val:Int?

…

init() { … }

deinit(){ … }

}

X is a superclass of Y

Y is a superclass of X

it doesn’t use class

X and Y is parent class

Which of the following keywords is used to define a constant?

var

let

constant

All of the above

ARC tracks how many , , and variables are in Swift?

Note: There may be more than one right answer.

properties

constants

functions

All of the above

What are the features of Memory Management in Swift?

In Swift with ARC we have no way to clean up the actual hardware ram. We can only make it possible for the OS to do that for us. One part is using the right code (optionals and weak) and the other part is creating time for the OS to do its job.

Imagine we have a function that runs on all threads indefinitely. It does one thing- loads an image, converts to black/white and saves. All images max at a couple of mb’s and the function creates no Software Memory Leaks. Because images don’t have a set size and might have different compression they don’t have the same footprint. This function will always crash your app.

This “Hardware” Memory Leak is caused by the function always taking the next available slot of memory.

The OS does not step into “actually clean the memory” because there is no idle time. Putting a delay between each pass completely fixes this.

All of the above

What is the correct way to declare Decomposed Tuple?

var rectangle = (x:0, y:0, width:20, height:50)

let (a, b, c, d) = rectangle

var (e, _, _, _) = rectangle

var rectangle = (x:0, y:0, width:20, height:50)

What is the correct way to compare the equality of two String type objects in Swift?

equalsTo

==

isEqual

>=<

AnyObject can represent:

an instance of any class type.

function types.

an instance of any type at all.

What is the name of the following function:

func potteryBarn (name: String, score: Int) -> String { return "Hello (name)! Your score is (score)." }

String

name: String, score: Int

potteryBarn

func

Which keyword defines a function?

func

function

procedure

let

extension

What is the type of Swift String, Dictionary, Array?

Class

Union

Enum

Structure

What will be the final value of "a.data" and "b.data" after following codes are executed?

struct A { var data: Int = 2 }

var a = A()

var b = a

var c = b

c.data = 10

a.data = 5

a.data = 10 and b.data = 2

a.data = 2 and b.data = 5

a.data = 5 and b.data = 5

a.data = 5 and b.data = 2

How will ARC handle "Country" instance and "country2" reference when "country1" is set to "nil"?

class Country{

let name: String

init(name: String){

self.name = name

}

}

var country1: Country?

var country2: Country?

country1 = Country(name: "Bangladesh")

country2 = country1

ARC will deallocate the Country instance but country2 will hold name it’s "Bangladesh"

ARC will not deallocate the Country instance but country2 will become "nil"

ARC will not deallocate the Country instance and country2 will hold it’s name "Bangladesh"

ARC will deallocate the Country instance and country2 will become "nil"

What is true about Memory management in Swift?

Swift uses Non-ARC so we need to handle the references manually.

Swift uses ARC but we still need to avoid reference cycles using weak and strong references etc.

Swift uses ARC so we don’t need to care about memory management at all.

NA

To which of these types does ARC apply?

Class

Structure

Enumeration

Basic types (String, Int, Bool)

Why are IBOutlets declared with a weak attribute by default?

IBOutlets are not declared with a weak attribute by default.

To save memory

To increase loading speed

They are already retained by the view

How could you call the following function that takes a closure as an argument using trailing closure syntax: ()) { // function body goes here }>

funcWithClosure ({ //closure’s body goes here })

funk funcWithClosure ({ //closure’s body goes here })

funcWithClosure() { //closure’s body goes here }

funcWithClosure { //closure’s body goes here )

How could the following closure be rewritten to use shorthand arguments? s2 } ) >

reversed = sorted(names, { $0 ,$1 in $0 > $1 } )

reversed = sorted(names, { $0 > $1 } )

reversed = sorted(names, { $0 ,$1 } )

reversed = sorted( { $0 > $1 } )

What is a trailing closure?

A closure expression that is called directly after another closure expression

A closure expression that is written outside of (and after) the parentheses of

the function call it supports.

A closure expression that is declared within the scope of another closure

expression.

A closure expression that is declared at the property of an object.

Which of the following statements is true regarding Swift closures and functions?

Functions and Closures are not related

A Function is a Closure declared within the scope of a Class

A Function is a named Closure

Closures can’t be used as arguments, Functions can

What are the available arithmetic overflow operators in Swift?

op+,op-,op*,op/,op%

&+,&-,&*,&/,&%

+,-,*,/,%

&, |, &&, ||

What is a specific custom infix operator?

it is a binary operator, taking a left and right hand argument

it is a unary operator written before its operand

it is a unary operator written after its operand

it is a reserved word that must be preceded with **

Which of following statements about functions is wrong?

In-out parameters might have a default value

Function might have multiple return values

Function might not have return values

Function names might be the same with another but at least one parameter should be different

In the below text, what type of return does the function ‘area’ give?

Class Square: NamedShape {

var sideLength: Double

func area() -> Double {

return sideLength*sideLength

}

}

Int

the area of a square

Double

area

In the below text, what is the class name?

Class Square: NamedShape {

var sideLength: Double

func area() -> Double {

return sideLength*sideLength

}

}

NamedShape

Square

class

Double

sideLength

In the below text, what is the name of the class’s only method?

Class Square: NamedShape {

var sideLength: Double

func area() -> Double {

return sideLength*sideLength

}

}

sideLength

area

Square

NamedShape

Double

What aspect of iOS development requires the use of NSOperation and/or Grand Central Dispatch (GCD)?

Multithreading

serial task

None

Message Sending

Which Swift Type is used to group multiple values into a single compound value? For example:

let compoundValue = (3, 5)

GroupObject

Tuple

Ordered

Struct

Swift can compile alongside what other language?

Objective C

Ruby

Scala

Erlang

What does Swift compile to?

C

C++

Ruby

Objective-C

Machine Code

Which of the following expressions can be used to rewrite the following UITableView instantiation in Swift?

<UITableView *myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];>"

let myTableView: UITableView = new UITableView(frame: CGRectZero, style:

.Grouped);

let myTableView: UITableView = UITableView.alloc().init(frame: CGRectZero, style:

.Grouped);

let myTableView: UITableView = UITableView(frame: CGRectZero, style:

.Grouped);

let myTableView: UITableView = UITableView(frame: CGRectZero, style:

UITableViewStyleGrouped)

Which of these operators is used to check whether or not two instances are identical?

==

=

equalsTo

===

identicalTo

In the bellow text, what is the super class name?

class Square: NamedShape {

var sideLenght: Double

func area() -> Double {

return sideLenght * sideLenght

}

}

Square

Double

area

sideLenght

NamedShape

In the bellow text, what is the property name?

class Square: NamedShape {

var sideLenght: Double

func area() -> Double {

return sideLenght * sideLenght

}

}

sideLenght

Square

NamedShape

area

NA

How do closures capture references to variables by default?

By weak reference

By strong reference

By unowned reference

By copy

To declare a function in swift you would use what keyword?

function

new func

var

let

func

Which of the folowing could be used to indicate the Function Type of the folowing function: func joinStrings(stringOne: String, stringTwo: String) -> String { return stringOne + stringTwo }

func(String, String -> String)

(String, String) -> String

{String, String} -> String

{String, String}(String)

What can be used in Swift to represent any kind of object?

Ob

id

AnyObject

Nothing

Swift Test Upwork 2019