Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Swift 3 Object-Oriented Programming
  • Table Of Contents Toc
Swift 3 Object-Oriented Programming

Swift 3 Object-Oriented Programming - Second Edition

By : Gaston C. Hillar
1 (1)
close
close
Swift 3 Object-Oriented Programming

Swift 3 Object-Oriented Programming

1 (1)
By: Gaston C. Hillar

Overview of this book

Swift has quickly become one of the most-liked languages and developers’ de-facto choice when building applications that target iOS and macOS. In the new version, the Swift team wants to take its adoption to the next level by making it available for new platforms and audiences. This book introduces the object-oriented paradigm and its implementation in the Swift 3 programming language to help you understand how real-world objects can become part of fundamental reusable elements in the code. This book is developed with XCode 8.x and covers all the enhancements included in Swift 3.0. In addition, we teach you to run most of the examples with the Swift REPL available on macOS and Linux, and with a Web-based Swift sandbox developed by IBM capable of running on any web browser, including Windows and mobile devices. You will organize data in blueprints that generate instances. You’ll work with examples so you understand how to encapsulate and hide data by working with properties and access control. Then, you’ll get to grips with complex scenarios where you use instances that belong to more than one blueprint. You’ll discover the power of contract programming and parametric polymorphism. You’ll combine generic code with inheritance and multiple inheritance. Later, you’ll see how to combine functional programming with object-oriented programming and find out how to refactor your existing code for easy maintenance.
Table of Contents (10 chapters)
close
close

Using map to transform values


The map method takes a closure as an argument, calls it for each item in the array, and returns a mapped value for the item. The returned mapped value can be of a different type from the item's type.

The following lines declare a new getUppercasedNames method for our previously coded GameRepository class that performs the simplest map operation. The code file for the sample is included in the swift_3_oop_chapter_07_21 folder:

    open func getUppercasedNames() -> [String] { 
      return getAll().map({ game in game.name.uppercased() }) 
    } 

The getUppercasedGames parameterless method returns Array<String>, specified with the [String] shortcut. The code calls the getAll method and calls the map method for the result with a closure that returns the name value for each game converted to uppercase. This way, the map method transforms each Game instance into String with its name converted to uppercase. The result is an Array<String&gt...

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Swift 3 Object-Oriented Programming
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon