This project was started as a collection of various useful ObjC methods - extensions to native Cocoa, UIKit and Foundation classes, extracted from several projects and gathered in one place for easier reuse. Since then we've used it in all our projects, and with each new one it keeps growing in new methods and classes. We're sharing it here now - perhaps someone else will find them useful too.
Add the whole directory to your Xcode project. You don't need to add the stuff on the root level, except
LunarToolkit.h, and you don't need the bridge support files (
Bridges/*), unless you're writing an app in MacRuby or
other similar language. If you do use MacRuby, then add the bridge support files too, otherwise you may get some hard to
spot bugs (like boolean methods returning true when they shouldn't, etc.).
The code is divided into several "modules" which can be enabled or disabled. Only the "Base" one is required, the rest is optional. You don't have to add the modules which you don't use into Xcode, though if you do, they will just be ignored (the compiler will skip them during build).
To import and configure LunarToolkit, add an import line to your
Prefix.pch file, and before that line declare
which modules you'd like to import (Cocoa and UIKit obviously shouldn't be used together):
#define LUNAR_TOOLKIT_ENABLE_COCOA #define LUNAR_TOOLKIT_ENABLE_MODELS #define LUNAR_TOOLKIT_ENABLE_NETWORK #define LUNAR_TOOLKIT_ENABLE_SECURITY #define LUNAR_TOOLKIT_ENABLE_UIKIT #import "LunarToolkit.h"
The configuration lines have to be added before the import, otherwise they won't matter.
Another thing you can configure this way is the choice of a JSON parsing library, if you need one. 4 libraries are supported: YAJL, JSON Framework, TouchJSON and JSONKit (see also a blog post that compares them).
To use one of them, add one of these lines to the prefix file:
#define LUNAR_TOOLKIT_USE_YAJL #define LUNAR_TOOLKIT_USE_JSON_FRAMEWORK #define LUNAR_TOOLKIT_USE_TOUCHJSON #define LUNAR_TOOLKIT_USE_JSONKIT
If you don't add any of these, methods related to JSON parsing will be unavailable.
For using some methods of LLModel, a JSON parser is required. The Network module requires ASIHTTPRequest library.
The Security module uses either SDKeychain by Steven Degutis or
SFHFKeychainUtils by Buzz Andersen (both are already bundled inside
LunarToolkit). Both of these require adding
Security.framework (provided in the SDK) to the project (see Add ->
- LLConstants - useful constants, e.g. for data size units, time units, and HTTP methods and status codes
- LLFoundationExtensions - categories adding methods to Foundation classes like NSString, NSArray, NSDate
- LLIntArray - an array that stores integers (actual integers, not NSNumbers)
- LLMacros - useful macros, e.g. for creating Foundation objects or sending notifications
- LLCocoaExtensions - categories adding useful methods to Cocoa classes
- LLAccount - class representing user accounts, provides methods for loading and saving data to settings and Keychain. Requires Security module.
- LLModel - base class for implementing models built from JSON data. Some methods require a JSON library.
- LLConnector - base class for building "server connectors" that send requests to a remote server and parse responses. Some methods require Models module and/or a JSON library.
- LLPathBuilder - a tool for building URLs with parameters
- LLRequest - represents a single request to a remote server
- LLResponse - represents a response to a request
- LLRestRouter - generates URLs for some helper methods in LLConnector. Requires Models module.
- LLSecurityExtensions - methods for setting and reading passwords from the Keychain (both on MacOSX and iOS)
- LLUIKitExtensions - categories adding useful methods to UIKit classes
If you want to add some new features, fix bugs etc.:
- if you're from Lunar Logic: ask me (@psionides) for access, commit on a branch, send me a pull request to merge into master
- otherwise: make a fork, push stuff to it, send me a pull request
Copyright by Jakub Suder & Lunar Logic Polska. Licensed under MIT license.