{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
Test: Swift - Tuples

5. var name = (“Thomas”, “J”, “Edison”) - if all you want is last name, which of following work?



Results
Congratulations! Correct Answer.
You Answered: None. If you took the test, your answer will show up here.
Correct Answer: var last = name.2; var (_, _, last) = name;
Explanation
You can obtain the last element of name tuple, by using name.2 (element 0 is first name, element 1 is middle name, and element 2 is the last name). You can assign it to another tuple, but chose to ignore the first two elements. Since name is not an array, name[2] doesn’t work. Since the parameters are not named in the tuple, name.last wouldn’t work.
Take the Test
Take the complete test on this topic. You will be able to review answers to questions and get a test score.

Take the Test


Question 5 of 5


Test is Based on this Article
icon-swift-article.jpg
Tags: tuples, types, swift
This article discusses the Tuple type which is introduced in Swift, but was not there in C or Objective-C.
icon-swift-test.jpg
Tags: tuples, types, swift
Test on tuples in Swift.

More Articles With Similar Tags
icon-swift-test.jpg
Tags: tuples, types, swift
Test on tuples in Swift.
icon-swift-series.jpg
This series of articles goes through the basics of Swift. It introduces Playgrounds and REPL; Variables and Constants; Int, Float, Bool; Tuples, Type Aliases, Type Inference, Type Safety, and more.
icon-swift-article.jpg
Tags: bool, types, swift
This article discusses the boolean types in Swift and contrasts with how these types are used in C and Objective-C.
icon-swift-test.jpg
Tags: bool, types, swift
Test on Boolean Types in Swift.
icon-swift-article.jpg
Tags: int, types, swift
This article goes through the usage of various integer types in Swift (including Int and UInt).
                                                                                                                                                                                                             
About  Contact  Privacy Policy  Site Map