Documentation • Issues • Pull Requests • Contributing • License
SwiftyHelpers is collection of handy Swift helper types we use in most of our iOS apps. Some are more broad, others only make sense in conjunction with common iOS / third-party APIs.
As we consider these helpers and the corresponding helper categorization pattern useful for others too, we've decided to put them up on GitHub. Yet, with them belonging into different categories and often requiring project-specific configuration, they aren't bundled in a single framework, but provided as single files (despite having some cross-references). In order to be able to build and test the project, all files are nonetheless part of a static cocoa touch library of no further use.
When using any of these types in an app, we suggest just using the same file structure as in this repo: Add a Helpers folder with three subfolders Managers, Actors and Infos. This way, even in larger projects, locating helpers will be straightforward.
As this repo is rather considered a loose collection of handy helpers that often even have to be modified depending on the app, single helpers aren't documented specifically. Please refer to the source files on how to use them.
You'll find three types of helpers in this repo:
- A Singleton Manager Class is a
class
with a singletonshared
property, a private initializer to disallow construction other than of the singletonshared
property, and various non-static interfaces like methods or properties, e. g.AppReviewManager
. - A Static Actor Class is a
class
with solely static interfaces and a private initializer to disallow construction. In contrast to singleton manager classes, it is expected not to offer any interfaces other than methods or computed properties. It is expected to always deliver the same result on execution, independent on app state. This means that configuration e. g. is not allowed. Also methods that should only be executed once, don't fit here. An example for a static actor class isDelay
, which only provides methods always doing the exact same thing without the need for any configuration. - A Static Info Struct is a
struct
with a solely static interface and a private initializer to disallow construction. It should only offer information on a specific matter (e. g. the app version (VersionInfo
)), but not do anything apart from possibly calculating some information.
Just looking at the helpers already included should help understanding this categorization pattern and gaining a feeling which helper type should be used for which need.
Note: The use of class
or struct
for the different helper types is carefully considered. While struct
is generally more lightweight and therefore encourageable to use, there are a few downsides to it:
- Only a
class
can inherit fromNSObject
, which is often needed for delegate conformances (SKProductsRequestDelegate
for instance). - Only a
class
can expose methods to the obj-c runtime using@objc
(needed for selectors). That's why both Singleton Managers and Static Actors are aclass
while Static Infos remain astruct
.
While there are helper types that can be used across multiple apps, many helpers are also app-specific. Nonetheless, those can still be implemented in accordance with the helper categorization & design pattern introduced for this repository.
As an inspiration, here are some more specific helper types used in our apps, just by name:
AlertManager
ColorManager
GameCenterManager
InAppPurchaseManager
InGameTextInfo
LaunchManager
PushNotificationsManager
ProgressIndicatorManager
QuickActionsManager
ScoreManager
SpotlightManager
UserInfo
As you can see, these helpers are mostly managers, which is quite natural given that managers are designed to be quite specific when interacting with some API, whilst actors and infos are more broad usually.
Contributions are welcome. See CONTRIBUTING.md for in-depth information.
This library is released under the MIT License. See LICENSE.md for details.