现在注册

登录

忘记密码

忘记密码? 请输入您的电子邮件地址. 您将收到一个链接,将创建通过电子邮件新密码.

添加后

你必须登录后添加 .

添加问题

您必须登录才能提问.

登录

现在注册

欢迎Scholarsark.com! 您的注册将授予您访问使用该平台的更多功能. 你可以问问题, 做出贡献或提供答案, 查看其他用户以及更多的个人资料. 现在注册!

LinkedIn 技能评估答案和问题 — Swift

迅速 has emerged as a powerful and intuitive programming language for developing iOS, 苹果系统, 和 watchOS 应用程序, 为开发人员提供一个现代化、高效的平台来构建创新软件. 在这份综合指南中, we’re thrilled to present a series of 技能评估问题答案 specifically tailored for 迅速 用户.

Whether you’re a seasoned developer looking to expand your capabilities or a beginner aiming to understand the basics of this powerful language, this resource is designed to help you become proficient in 迅速 及其应用. Join us as we explore the core concepts of 迅速 程序设计, including optionals, closures, 协议, 和更多, empowering you to leverage the full potential of this essential tool for your iOS and macOS projects.

第一季度. What is this code an example of?

let val = (Double)6
  • A syntax issue
  • Typecasting
  • 任务
  • Initialization

参考: The Swift Programming Language: Language Guide: 基础知识: Constants and Variables

Q2. What is the error in this code?

let x = 5
guard x == 5 { return }
  • guard is missing the else
  • Nothing is wrong
  • guard is missing a then
  • The comparison is wrong

参考: The Swift Programming Language: Language Guide: 控制流: Early Exit

Q3. What is the raw/underlying type of this enum?

enum Direction {
  case north, south, east, west
}
  • There is none
  • String
  • Any
  • Int

参考: The Swift Programming Language: Language Guide: Enumerations: Raw Values

第四季度. Why is dispatchGroup used in certain situations?

  • It allows multiple synchronous or asynchronous operations to run on different queues.
  • It allows track and control execution of multiple operations together.
  • It allows operations to wait for each other as desired.
  • 所有这些答案.

参考: Apple Developer: 文档: Dispatch: Dispatch Group

Q5. What is this code an example of?

let val = 5
print("value is: \(val)")
  • String interpolation
  • String compilation
  • Method chaining
  • 字符串连接

参考: The Swift Programming Language: Language Guide: Strings and Characters: String Interpolation

Q6. What are the contents of vals after this code is executed?

var vals = [10, 2]
vals.sort { (s1, s2) -> Bool in
  s1 > s2
}
  • [10, 2]
  • [2, 10]
  • nil
  • This code contains an error

参考: Apple Developer: Documentations: 迅速: 大批: 种类()

Q7. What does this code print?

typealias Thing = [String: Any]
var stuff: Thing
print(type(of: stuff))
  • Dictionary<String, Any>
  • Dictionary
  • Error
  • Thing

参考: The Swift Programming Language: Language Reference: 类型: Type Identifier

Q8. What is the value of y?

let x = ["1", "2"].dropFirst()
let y = x[0]
  • This code contains an error
  • 1
  • 2
  • nil

解释
dropFirst()Swift.Collection.Array returns a type of ArraySlice<Element>
as in the documentation pages:
@inlinable public func dropFirst(_ k: Int = 1) -> ArraySlice<Element>

The ArraySlice type makes it fast and efficient for you to perform operations on sections of a larger array. Instead of copying over the elements of a slice to new storage, an ArraySlice instance presents a view onto the storage of a larger array. And because ArraySlice presents the same interface as Array, you can generally perform the same operations on a slice as you could on the original array.

Slices Maintain Indices
Unlike Array and ContiguousArray, the starting index for an ArraySlice instance isn’t always zero. Slices maintain the same indices of the larger array for the same elements, so the starting index of a slice depends on how it was created, letting you perform index-based operations on either a full array or a slice.
The above code returns a slice of value ["2"] but the index did not change. let y = x[1] would give the expected result.
To safely reference the starting and ending indices of a slice, always use the startIndex and endIndex properties instead of specific values.
参考

Q9. What is the value of test in this code?

var test = 1 == 1
  • true
  • YES
  • 1
  • This code contains an error

参考: The Swift Programming Language: Language Guide: Basic Operators: Comparison Operators

辅酶Q10. What is the value of y?

var x: Int?
let y = x ?? 5
  • 5
  • 0
  • nil
  • This code contains an error

参考: The Swift Programming Language: Language Guide: Basic Operators: Nil-Coalescing Operators

Q11. What is the type of this function?

func add(a: Int, b: Int) -> Int { return a+b }
  • Int
  • (Int, Int) -> Int
  • Int<Optional>
  • Functions don’t have types.

参考: The Swift Programming Language: Language Guide: 功能: Function Types

Q12. What is the correct way to call this function?

func myFunc(_ a: Int, b: Int) -> Int {
  return a + b
}
  • myFunc(5, b: 6)
  • myFunc(5, 6)
  • myFunc(a: 5, b: 6)
  • myFunc(a, b)

参考: The Swift Programming Language: Language Guide: 功能: Function Argument Labels and Parameter Names

Q13. The Codable protocol is _?

  • A combination of EncodableDecodable
  • Not a true protocol
  • Required of all classes
  • Automatically included in all classes

参考:

Q14. What is the type of value1 in this code?

let value1 = "\("test".count)"
  • String
  • Int
  • null
  • test.count

参考: The Swift Programming Language: Language Guide: Strings and Characters: String Interpolation

Q15. When a function takes a closure as a parameter, when do you want to mark is as escaping?

  • When it’s executed after the function returns
  • When it’s scope is undefined
  • When it’s lazy loaded
  • 所有这些答案

参考: The Swift Programming Language: Language Guide: Closures: Escaping Closures

Q16. What’s wrong with this code?

class Person {
  var name: String
  var address: String
}
  • Person has no initializers.
  • Person has no base class.
  • var name is not formatted correctly.
  • address is a keyword.

参考: The Swift Programming Language: Language Guide: Initialization: Class Inheritance and Initialization

Q17. What is the value of names after this code is executed?

let names = ["Bear", "Joe", "Clark"]
names.map { (s) -> String in
  return s.uppercased()
}
  • ["BEAR", "JOE", "CLARK"]
  • ["B", "J", "C"]
  • ["Bear", "Joe", "Clark"]
  • This code contains an error.

Q18. What describes this line of code?

let val = 5
  • A constant named val of type Int
  • A variable named val of type item
  • A constant named val of type Number
  • A variable named val of type Int

参考: The Swift Programming Language: Language Guide: 基础知识: Type Safety and Type Inference

Q19. What is the error in this code?

extension String {
  var firstLetter: Character = "c" {
    didSet {
      print("new value")
    }
  }
}
  • Extensions can’t add properties.
  • Nothing is wrong with it.
  • didSet takes a parameter.
  • c is not a character.

参考: The Swift Programming Language: Language Guide: 扩展: Computed Properties

Q20. didSet and willSet are examples of _?

  • Property observers
  • Key properties
  • 所有这些答案
  • newOld value calls

参考: The Swift Programming Language: Language Guide: 物产

Q21. What is wrong with this code?

self.callback = {
  self.attempts += 1
  self.downloadFailed()
}
  • 用于 self inside the closure causes retain cycle.
  • You cannot assign a value to a closure in this manner.
  • You need to define the type of closure explicitly.
  • There is nothing wrong with this code.

参考: The Swift Programming Language: Language Guide: Automatic Reference Counting: Strong Reference Cycles for Closures

Q22. How many values does vals have after this code is executed?

var vals = Set<String> = ["4", "5", "6"]
vals.insert("5")
  • Eight
  • This code contains an error.

参考: The Swift Programming Language: Language Guide: Collection Types: 套

Q23. How can you avoid a strong reference cycle in a closure?

  • Use a capture list to set class instances of weak 要么 unowned.
  • You can’t, there will always be a danger of strong reference cycles inside a closure.
  • Initialize the closure as read-only.
  • Declare the closure variable as lazy.

参考: The Swift Programming Language: Language Guide: Automatic Reference Counting

Q24. What is wrong with this code?

if let s = String.init("some string") {
  print(s)
}
  • 这个 String initializer does not return an optional.
  • String does not have an initializer that can take a String.
  • = is not a comparison.
  • Nothing is wrong with this code.

参考: The Swift Programming Language: Language Guide: 基础知识: Optionals

Q25. Which code snippet correctly creates a typealias closure?

  • typealias CustomClosure = () -> ()
  • typealias CustomClosure { () -> () }
  • typealias CustomClosure -> () -> ()
  • typealias CustomClosure -> () {}

参考: The Swift Programming Language: Language Reference: Declarations: Type Alias Declaration

Q26. How do you reference class members from within a class?

  • self
  • instance
  • class
  • this

参考: The Swift Programming Language: Language Guide: 方法: Instance Methods

Q27. All value types in Swift are _ 在引擎盖下?

  • Structs
  • 班级
  • Optionals
  • Generics

参考: The Swift Programming Language: Language Guide: Structures and Classes

Q28. What is the correct way to add a value to this array?

var strings = [1, 2, 3]
  • 所有这些答案
  • strings.append(4)
  • strings.insert(5, at: 1)
  • strings += [5]

参考: The Swift Programming Language: Language Guide: Collection Types: 数组

Q29. How many times will this loop be executed?

for i in 0...100 {
  print(i)
}
  • 0
  • 101
  • 99
  • 100

参考:

Q30. What can AnyObject represent?

  • An instance of any class
  • An instance of function type
  • 所有这些答案
  • An instance of an optional type

参考: The Swift Programming Language: Language Guide: Type Casting: Type Casting for Any and AnyObject

Q31. What is the value of t after this code is executed?

let names = ["Larry", "Sven", "Bear"]
let t = names.enumerated().first().offset
  • This code does not compile. / This code is invalid.
  • 0
  • 1
  • Larry

参考:

Q32. What is the value of test after this code executes?

let vt = (name: "ABC", val: 5)
let test = vt.0
  • ABC
  • 0
  • 5
  • name

参考:

Q33. What is the base class in this code?

class LSN: MMM {
}
  • MMM
  • LSN
  • There is no base class.
  • This code is invalid.

参考: The Swift Programming Language: Language Guide: 遗产: Subclassing

Q34. What does this code print to the console?

var userLocation: String = "Home" {
  willSet(newValue) {
    print("About to set userLocation to \(newValue)...")
  }

  didSet {
    if userLocation != oldValue {
      print("userLocation updated with new value!")
    } else {
      print("userLocation already set to that value...")
    }
  }
}

userLocation = "Work"
  • About to set userLocation to Work... userLocation updated with new value!
  • About to set userLocation to Work... userLocation already set to that value...
  • About to set userLocation to Home... userLocation updated to new value!
  • Error

参考: The Swift Programming Language: Language Guide: 物产: Property Observers

Q35. What must a convenience initializer call?

  • A base class convenience initializer
  • Either a designated or another convenience initializer
  • A designated initializer
  • None of these answers

参考: The Swift Programming Language: Language Guide: Initialization: Class Inheritance and Initialization

Q36. Which object allows you access to specify that a block of code runs in a background thread?

  • DispatchQueue.visible
  • DispatchQueue.global
  • errorExample need to be labeled as throws.
  • DispatchQueue.background

参考: Apple Developer: 文档: Dispatch: DispatchQueue

Q37. What is the inferred type of x?

let x = ["a", "b", "c"]
  • String[]
  • Array<String>
  • Set<String>
  • Array<Character>

参考: The Swift Programming Language: Language Guide: Collection Types: 数组

Q38. What is the value of oThings after this code is executed?

let nThings: [Any] = [1, "2", "three"]
let oThings = nThings.reduce("") { "\($0)\($1)" }
  • 11212三
  • 115
  • 12三
  • 没有, this code is invalid.

参考: Apple Developer: 文档: 迅速: 大批: reduce(_:_:)

Q39. How would you call a function that throws errors and also returns a value?

  • !try
  • try?
  • try!
  • ?try

参考: The Swift Programming Language: Language Guide: 错误处理: Handling Errors

Q40. What is wrong with this code?

protocol TUI {
  func add(x1: Int, x2: Int) -> Int {
    return x1 + x2
  }
}
  • Protocol functions cannot have return types.
  • Protocol functions cannot have implementations.
  • Nothing is wrong with it.
  • add is a reserved keyword.

参考:

Q41. In this code, 什么是 wheelsdoors examples of?

class Car {
  var wheels: Int = 4
  let doors = 4
}
  • Class members
  • This code is invalid
  • Class fields
  • Class properties

参考:

Q42. How do you designated a failable initializer?

  • You cannot
  • deinit
  • init?
  • init

参考:

Q43. What is printed when this code is executed?

let dbl = Double.init("5a")
print(dbl ?? ".asString()")
  • five
  • 5a
  • .asString()
  • 5

参考:

Q44. In the function below, 什么是 thistoThat examples of?

func add(this x: Int, toThat y: Int) { }
  • None of these answers
  • Local terms
  • Argument labels
  • Parameters names

参考: The Swift Programming Language: Language Guide: 功能

Q45. What is wrong with this code?

for (key, value) in [1: "one", 2: "two"] {
  print(key, value)
}
  • The interaction source is invalid
  • The interaction variable is invalid
  • There is nothing wrong with this code
  • The comma in the print is misplaced

参考: The Swift Programming Language: Language Guide: 控制流: For-In Loops

Q46. Which of these choices is associated with unit testing?

  • XCTest
  • 所有这些答案
  • @testable
  • XCTAssert

参考:

Q47. In the code below, what is width an example of?

class Square {
  var height: Int = 0
  var width: Int {
    return height
  }
}
  • This code contains error
  • A closure
  • A computed property
  • Lazy loading

参考:

Q48. What data type is this an example of?

let vals = ("val", 1)
  • 一本字典
  • A tuple
  • An optional
  • This code contains error

参考:

Q49. What is wrong with this code?

var x = 5
x = 10.0
  • You cannot assign a Double to a variable of type Int
  • x is undefined
  • x is a constant
  • x has no type

参考: The Swift Programming Language: Language Guide: 基础知识

辅酶50. What will this code print to the console?

var items = ["a": 1, "b": 2, "c": "test"] as [String: Any]
items["c"] = nil
print(items["c"] as Any)
  • 任何
  • 测试
  • 1,2,3
  • nil

参考:

Q51. What is wrong with this code?

let val = 5.0 + 10
  • There is nothing wrong with this code
  • val is a constant and cannot be changed
  • 5.010 are different types
  • There is no semicolon

参考: The Swift Programming Language: Language Guide: 基础知识: Type Safety and Type Inference

Q52. How many parameters does the initializer for Test have?

struct Test {
  var score: Int
  var date: Date
}
  • Zero
  • This code contains an error
  • Structs do not have initializers

参考: The Swift Programming Language: Language Guide: Initialization

Q53. What prints to the console when executing this code?

let x = try? String.init("test")
print(x)
  • nil
  • 没有 – this code contains an error
  • 可选的(“测试”)
  • 测试

参考:

Q54. How can you sort this array?

var vals = [1, 2, 3]
  • vals.sort { $0 < $1 }
  • vals.sort { (s1, s2) in s1 < s2 }
  • vals.sort(by: <)
  • 所有这些答案

参考: Apple Developer: 文档: 迅速: 大批: 种类()

Q55. DispatchQueue.main.async takes a block that will be

  • Not executed
  • Executed in the main queue
  • None of these answers
  • Executed on the background thread

参考: Apple Developer: 文档: Dispatch: DispatchQueue: async(组:qos:flags:执行:)

Q56. When is deinit called?

  • When a class instance needs memory
  • 所有这些答案
  • When the executable code is finished
  • When a class instance is being removed from memory

参考: The Swift Programming Language: Language Guide: Deinitialization

Q57. How do you declare an optional String?

  • String?
  • Optional[String]
  • [String]?
  • ?String

参考: The Swift Programming Language: Language Guide: 基础知识: Optionals

Q58. How many times this code will be executed? / How many times will this loop be performed?

for i in ["0", "1"] {
  print(i)
}
  • This code does not compile

参考: The Swift Programming Language: Language Guide: 控制流: For-In Loops

Q59. What does this code print?

let names = ["Bear", "Tony", "Svante"]
print(names[1] + "Bear")
  • 1Bear
  • BearBear
  • TonyBear
  • 没有, this code is invalid

参考:

Q60. What is true of this code?

let name: String?
  • name can hold only a string value.
  • name can hold either a string or nil value.
  • Optional values cannot be let 常数.
  • Only non-empty string variables can be stored in name.

参考: The Swift Programming Language: Language Guide: 基础知识: Optionals

Q61. What is the value of val after this code is executed?

let i = 5
let val = i * 6.0
  • This code is invalid.
  • 6
  • 30
  • 0

参考: The Swift Programming Language: Language Guide: 基础知识: Type Safety and Type Inference

Q62. What does this code print?

enum Positions: Int {
  case first, second, third, other
}

print (Positions.other.rawValue)
  • 3
  • 0
  • 其他
  • nil

参考: The Swift Programming Language: Language Guide: 基础知识: Raw Values

Q63. What is printed to the console when this code is executed?

"t".forEach { (char) in
  print(char)
}
  • nil
  • 没有, since the code contains an error
  • zero

参考:

Q64. What prints when this code is executed?

let s1 = ["1", "2", "3"]
  .filter { $0 > "0" }
  .sorted { $0 > $1 }
print(s1)
  • []
  • [“3”, “2”, “1”]
  • [321]
  • [“1”, “2”, “3”]

参考:

Q65. What enumeration feature allows them to store case-specific data?

  • Associated values
  • Integral values
  • Raw values
  • Custom values

参考: The Swift Programming Language: Language Guide: Enumerations: Associated Values

Q66. In the code below, AOM must be a(n)?

class AmP: MMM, AOM { }
  • Class
  • 协议
  • Enumeration
  • Struct

参考:

Q67. What is the value of numbers in the code below?

let numbers = [1, 2, 3, 4, 5, 6].filter { $0 % 2 == 0 }
  • [1, 3, 5]
  • []
  • [2, 4, 6]
  • nil

参考: Apple Developer: 文档: 迅速: Swift Standard Library: 收藏品: Sequence and Collection Protocols: 序列: 筛选()

Q68. What is the type of vals in this code?

let vals = ["a", 1, "Hi"]
  • 大批(char)
  • [任何]
  • 大批
  • [Generic]

参考: The Swift Programming Language: Language Guide: Type Casting

Q69. How can you extract val to x in tuple vt

let vt = (name: "ABC", val: 5)
  • let x = vt.1
  • 所有这些答案
  • let x = vt.val
  • 让 (_, X) = vt

参考: The Swift Programming Language: Language Guide: 基础知识: 元组

Q70. What is the type of x?

let x = try? String.init(from: decoder)
  • String
  • String?
  • String!
  • 尝试?

参考: The Swift Programming Language: Language Guide: 错误处理: Handling Errors

Q71. How many times is this loop executed?

let loopx = 5
repeat {
  print (loopx)
} while loopx < 6
  • Zero
  • Five
  • Infinite

参考: The Swift Programming Language: Language Guide: 控制流: While Loops

Q72. How many values does vals have after this code is executed?

var vals: Set<String> = ["4", "5", "6"]
vals.insert("5")
  • This code contains an error.
  • Eight

参考: The Swift Programming Language: Language Guide: Collection Types: 套

Q73. What is the base class in this code ?

class LSN: MMM{ }

  • MMM
  • LSN
  • There is no base class.
  • This code is invalid.

作者

  • 海伦·贝西

    你好, I'm Helena, 一位热衷于在教育领域发布有洞察力内容的博客作者. 我相信教育是个人和社会发展的关键, 我想与所有年龄和背景的学习者分享我的知识和经验. 在我的博客上, 您会找到有关学习策略等主题的文章, 在线教育, 职业指导, 和更多. 我也欢迎读者的反馈和建议, 所以请随时发表评论或联系我. 我希望您喜欢阅读我的博客并发现它有用且鼓舞人心.

    查看所有帖子

关于 海伦·贝西

你好, I'm Helena, 一位热衷于在教育领域发布有洞察力内容的博客作者. 我相信教育是个人和社会发展的关键, 我想与所有年龄和背景的学习者分享我的知识和经验. 在我的博客上, 您会找到有关学习策略等主题的文章, 在线教育, 职业指导, 和更多. 我也欢迎读者的反馈和建议, 所以请随时发表评论或联系我. 我希望您喜欢阅读我的博客并发现它有用且鼓舞人心.

发表评论