TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Feb 2016 |
SPMSupports SPM | ✓ |
Maintained by Tom Baranes.
ReusableObjects
is the easiest way to create an object once, and re-used it as much as possible. It’s allow you to avoid several allocation / initialization of expensive objects such as NSDateFormatter
, NSNumberFormatter
… or any of your custom objects.
Available for iOS, OS X, and tvOS.
let reuseIdentifier = "kDateFormatterIdentifier"
NSDateFormatter.registerObjectWithIdentifier(reuseIdentifier)
if let dateFormatter = NSDateFormatter.dequeueReusableObjectWithIdentifier(identifier) as? NSDateFormatter,
reusedDateFormatter = NSDateFormatter.dequeueReusableObjectWithIdentifier(identifier) as? NSDateFormatter {
print("\(dateFormatter) vs \(reusedDateFormatter)") // <NSDateFormatter: 0x7fd1307125c0> vs <NSDateFormatter: 0x7fd1307125c0>
}
Check out the demo project to see other examples.
ReusableObjects is available on SPM. Just add the following to your Package file:
import PackageDescription
let package = Package(
dependencies: [
.Package(url: "https://github.com/tbaranes/ReusableObjects.git", majorVersion: 1)
]
)
Just drag the Source/*.swift
files into your project.
static func registerObjectWithIdentifier(reuseIdentifier: String)
public func registerObjectWithIdentifier(reuseIdentifier: String)
Attempts to register a class to reuse it anywhere in your application. Does nothing if the current object or identifier is not valid.
The reuseIdentifier
parameter must not be nil and must not be an empty string.
static func unregisterObjectWithIdentifier(reuseIdentifier: String)
Unregister the object located by its identifiers. Doesn nothing if the object doesn’t exist.
static func dequeueReusableObjectWithIdentifier(reuseIdentifier: String) -> AnyObject?
Returns a reusable NSObject
object located by its identifier.
If any object found, it will register the object before returning the object registered or nil if an error occured.
ReusableObjects is available under the MIT license. See the LICENSE file for more info.