0Pricing
Swift Academy · Lesson

Common APIs — prefix/suffix/contains, split/join

Use practical String APIs: hasPrefix/hasSuffix/contains, split into parts, and join arrays back with separators.

Overview

Swift offers handy String helpers for everyday tasks: hasPrefix, hasSuffix, contains, split, and joined. You'll combine them safely on small screens.

Prefix/Suffix/Contains

Check beginnings, endings, or substring presence with hasPrefix, hasSuffix, and contains.

let path = "/usr/local/bin"
print(path.hasPrefix("/usr"))   // true
print(path.hasSuffix("bin"))    // true
print(path.contains("local"))   // true

All lessons in this course

  1. Strings & Unicode — graphemes, indices, substrings, APIs
  2. Common APIs — prefix/suffix/contains, split/join
  3. Performance notes — copy-on-write
← Back to Swift Academy