Do you know that? Think of the user and NOT yourself while designing. next

Contact Email: teammmrem@yahoo.com

<< All Upwork (oDesk) and Elance Tests << Upwork (oDesk) test answers << General Programming category

Test answers for Swift Test 2016

(40) Last updated: June 23
Upwork (oDesk) • General Programming
Questions and answers are regularly updated. Answered and not answered tests questions.

This helps getting job: Hundreds of (cover letter examples , interview questions , profile samples ) • Earn on Upwork (oDesk)
Job assistance: jobs popularityfreelance rates

Popular test answers: HTML, .Net, CSS, English, SEO, Photoshop, iOS, Java, Android, Ruby, Python, JavaScript

See all 6 tests answers updated

Find Upwork (oDesk) and Elance test answers on this website:



Collapse | Expand

40 Answered Test Questions:

1. Which  is the wrong definition of a protocol in Swift?

Answers:

• protocol SomeProtocol { var first: Int{ get } }

• protocol SomeProtocol { var first: Int{ set } }

• protocol SomeProtocol { var first: Int { get set } }

• protocol SomeProtocol { var first: Int { get set } var second: Int { get } }

2. Which of the following structures has both computed and stored properties?

Answers:

• struct Rect { var origin = CGPointZero var center: CGPoint { get { // } set { // } } }

• struct Rect { var center: CGPoint { get { // } set { // } } }

• struct Rect { let origin = CGPointZero }

• struct Rect { var origin = CGPointZero var center: CGPointMake(0,0) }

3. What is the name of the Xcode generated header file used to import Swift classes into an Objective-C Class given a product module named Example?

Answers:

• ExampleSwift.h

• Example.Swift.h

• Example+Swift.h

• Example-Swift.h

4. Considering var index = UInt8.max, which of the following operation results to the value of zero for var index?

Answers:

• index = index &- 1

• index = index &+ 1

• index = index &* 1

• index = index &/ 255

5. Which of these is a valid syntax for iterating through the keys and values of a dictionary?
let dictionary = [keyOne : valueOne, keyTwo : valueTwo]

Answers:

• for (key, value) in dictionary { println("Key: \(key) Value: \(value)") }

• for (key, value) in enumerate(dictionary) { println("Key: \(key) Value: \(value)") }

• for (key, value) in (dictionary.keys, dictionary.values) { println("Key: \(key) Value: \(value)") }

• for (key, value) in dictionary.enumerate() { println("Key: \(key) Value: \(value)") }

6. All Swift classes must inherit from which root class?

Answers:

• Swift classes do not require a root class.

• NSObject

• @ObjC

• Root

7. What does a retainCount represent in ARC?

Answers:

• The current number of strong references to an object.

• The current number of instances of an object.

• The total number of objects currently being retained in memory.

• The total number of times an object has been allocated.

8. Which of these statements is a valid way to extend the capabilities of our theoretical class, MyClass to conform to protocol MyProtocol?

Answers:

• extension MyClass(MyProtocol) { }

• extension MyClass, prot MyProtocol { }

• extension MyClass: MyProtocol { }

• extension MyClass, MyProtocol { }

9. What is the name of the Swift language feature that Objective-C Blocks are translated into?

Answers:

• Lambda

• Callback

• Closure

• Selector

10. Which keyword is used on a function in an enumeration to indicate that the function will modify 'self'?

Answers:

• modifier

• mutating

• mutable

• mod

• mut

11. Which is correct for Enumerations?

Answers:

• Enumerations can define initializers.

• Enumerations cannot conform to protocols.

• Enumerations cannot conform to protocols.

12. Which one creates a dictionary with a key type of Integer and value of String?

Answers:

• var dict:[Int: String] = ["one":1]

• var dict: [Int: String] = [1:"one"]

• var dict: [String: Int] = [1:"one"]

• var dict = ["one":1]

13. Which of these is a valid definition of a generic function that incorporates inout parameters in Swift?

Answers:

• func swap<T>(inout a: T, inout b: T) { let temp = a a = b b = temp }

• func swap<U,T>(inout a: U, inout b: T) { let temp = a a = b b = temp }

• func swap<U,T>( a: U, b: T) { let temp = a a = b b = temp }

• func swap<T>( a: T, b: T) { let temp = a a = b b = temp }

14. Which of these is an appropriate syntax for dispatching a heavy operation to a background thread?

Answers:

• dispatch_async(DISPATCH_QUEUE_PRIORITY_BACKGROUND), { self.heavyOperation() })

• dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), { self.heavyOperation() })

• DISPATCH_QUEUE_PRIORITY_BACKGROUND({ self.heavyOperation() })

• dispatch_async({ self.heavyOperation() })

15. Which one is the correct keyword for defining a constant in Swift?

Answers:

• const

• contant

• final

• let

• def

16. If we have a class named MyClass with a nested enum called Status, declared like so:
class MyClass {
    enum Status {
        case On, Off
    }
}
How would one indicate that a variable is an enum of type Status outside the context of MyClass?

Answers:

• var status: MyClass.Status = .On

• var status: Status = .On

• var status: MyClass<Status> = .On

• var status: MyClass(Status) = .On

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

Answers:

• func(String, String -> String)

• (String, String) -> String

• {String, String} -> String

• {String, String}(String)

18. Which of the following statements could be used to determine if a given variable is of String type?

Answers:

• if String.hierarchy(unknownVariable) { }

• if unknownVariable is String { }

• if unkownVariable: String { }

• if (String)unknownVariable { }

19. Which of these could be an appropriate protocol declaration in Swift?

Answers:

• @objc protocol someProtocal { optional var first: Int { get } }

• @objc protocol someProtocal { optional var first: Int { set } }

• protocol someProtocal { optional var first: Int { get } }

• protocol someProtocal { var first: Int { set } }

20. In context of a Swift subscript, which of the following is correct?

Answers:

• struct MyStruct { var myStr = [String]() subscript (index : Int) -> String{ get{ return myStr[index] } set{ myStr[index] = newValue } } }

• struct MyStruct { var myStr = [String]() subscript (index : Int) -> Int{ get{ return myStr[index] } set(newValue){ myStr[index] = newValue } } }

• struct MyStruct { var myStr = [String]() subscript (index : Int) -> String{ get(){ return myStr[index] } set(newValue){ myStr[index] = newValue } } }

• struct MyStruct { var myStr = [String] subscript (index : Int) -> String{ get(){ return myStr[index] } set(newValue){ myStr[index] = newValue } } }

21. What is used to import Objective-C files into Swift?

Answers:

• Objective-C classes are automatically imported.

• Objective-C classes are imported in the Swift file using the class.

• Objective-C classes are imported via a Bridging Header.

• Objective-C classes import themselves by declare @SwiftImportable.

22. What keyword is used to indicate a custom operator that will appear in between two targets, similar to the addition operator in this example?
var sum = 10 + 10

Answers:

• @inter

• between

• infix

• @center

23. What is the output of this segment of code ?
var x = 0

for index in 1...5 {
    ++x
}
println("\(x)")

Answers:

• 0

• compile error

• 5

• 4

24. What is the name of the deinitializer in a Class declaration?

Answers:

• deinit

• dealloc

• release

25. Which is correct regarding Swift enumeration members when they are defined?

Answers:

• Members are assigned a default integer value.

• Members are assigned a random default integer value.

• Members are not assigned default integer values.

26. What type of object are Swift Structures?

Answers:

• Reference Type

• Memory Type

• Abstract Type

• Value Type

27. Which keyword in the context of a Switch statement is required to force the execution of a subsequent case?

Answers:

• fallthrough

• continue

• break

• return

28. What is the type of Swift Enumerations?

Answers:

• Reference type

• Class type

• Collection type

• Value type

29. Given that we have defined myChar like so :
let myChar: Character = "b"
Which code segment can be considered a complete Switch statement and will run without any error?

Answers:

• switch myChar { case "a","A": println("The letter A") case "b","B": println("The letter A") }

• switch myChar { case "a": println("The letter A") }

• switch myChar { case "a": case "A": println("The letter A") default: println("Not the letter A") }

• switch myChar { case "a","A": println("The letter A") default: println("Not the letter A") }

30. Can enumeration type have methods?

Answers:

• Enumerations can have methods associate with them.

• Enumerations can have only member values.

31. Which of these is an appropriate syntax for declaring a function that takes an argument of a generic type?

Answers:

• func genericFunction(argument: T<Generic>) { }

• func genericFunction<T>(argument) { }

• generic func genericFunction(argument: T) { }

• func genericFunction<T>(argument: T) { }

32. Which of these is not a valid property declaration in Swift?

Answers:

• final let x = 0

• final lazy let x = 0

• final lazy var x = 0

• final var x = 0

33. Which of the following declares a mutable array in Swift?

Answers:

• var x = [Int]

• let x = [Int]

• var x = [Int]()

• let x = [Int]()

34. Which one of the below functions definitions is wrong considering Swift language?

Answers:

• func haveChar(#string: String, character: Character) -> (Bool)

• func mean(numbers: Double...) -> Double

• func minMax(array: [Int]) -> (min: Int, max: Int)?

• func minMax(array: [Int]) -> (min: Int?, max: Int?)

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

Answers:

• let

• var

• const

• lazy

36. Which is used for down casting?

Answers:

• as!

• is

• is?

• as?

37. What attribute can be used to allow a protocol to contain optional functions and to be used in ObjC?

Answers:

• objective_bridge

• ObjC

• _objc

• @objc

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

Answers:

• Bool

• Array

• Int, String, Float

• Dictionary

39. Which keyword do you use to declare enumeration?

Answers:

• var

• enum

• struct

• case

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

Answers:

• Semi-colon

• Colon

• Comma

• Slash

• Point