Do you need help on a specific subject? Use the contact form (Request a blog entry) on the right hand side.

Swift Type Extensions


This page contains links to blogposts that contain extensions for predefined Swift types.

String extensions

fixIndex
This extension introduces an operation to rebase a String.Index if the originating string of an index variable has changed. This is important when changing a string's length because the indexes before the string update are still using the older string endIndex.

isLowercaseCharacterAtIndex
isUppercaseCharacterAtIndex
These two extensions check if a UTF16 character at the given String.Index is present in the NSCharacterSet lowercase resp uppercase.

replaceCharacterAtIndex:with
Only available for mutable strings, this extension replaces a character in the string with a given character.

changeCaseOfCharacterAtIndex
Only available for mutable strings, this extension works only on lowercase or uppercase characters and reverses it case.

Array extensions

removeObject
This extension reintroduces the removeObject operation (from the NSArray) to the Swift array type.

NSEventModifierFlags extensions

NSEventModifierFlags extensions: isSet and isNotSet
These functions make working with the even modifier flags more readable.

UInt8 extensions

Bit access for a the UInt8
Accessing the bits as a set of 8 Bools in a tuple.

OptionSetType extensions

Factory method
A clean looking factory constructor when creating an option with multiple selections (OR-ing)

Comparable extension

Limiting functions
Some functions that can clip the value of a Comparable to either a maximum or minimum limit (or both).

No comments:

Post a Comment