Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Beginning Swift
  • Toc
  • feedback
Beginning Swift

Beginning Swift

By : Rob Kerr, Kåre Morstøl
4 (1)
close
Beginning Swift

Beginning Swift

4 (1)
By: Rob Kerr, Kåre Morstøl

Overview of this book

Take your first foray into programming for Apple devices with Swift.Swift is fundamentally different from Objective-C, as it is a protocol-oriented language. While you can still write normal object-oriented code in Swift, it requires a new way of thinking to take advantage of its powerful features and a solid understanding of the basics to become productive.
Table of Contents (10 chapters)
close

Challenge


Here's the final challenge; the Standard Library has methods for splitting a string over a single character, or a function that takes a single character and returns a Boolean. However, it doesn't have any methods for splitting a string over a substring, or doing it lazily.

Create a new method, which can be used on lazy strings and substrings, and takes a separator (String) and optionally String.CompareOptions and Locale, and returns a lazy sequence of the ranges between each occurrence of the separator in the original string/substring.

There are several ways of achieving this. The following hints describe one solution which uses some of the methods we have created in this course. Try and see if you can complete this by using as few hints as possible.

Hints:

  • We can find the ranges of the separators first, and then invert them to get the ranges of the spaces between the separators.

  • Use the lazy allranges method we created in Lesson 6.

  • Break...

bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete