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")) // trueAll lessons in this course
- Strings & Unicode — graphemes, indices, substrings, APIs
- Common APIs — prefix/suffix/contains, split/join
- Performance notes — copy-on-write