Latest 0.2
Homepage https://github.com/hfossli/IVYPool
License MIT
Platforms ios 7.0, requires ARC
Frameworks Foundation
Authors

A thread safe pool factory for iOS. Store, get and create objects on demand.

Installation

pod 'IVYPool'
Import in swift
import IVYPool
Import in Objective-C
#import <IVYPool/IVYPool.h>

API

...
@property (nonatomic, copy, readwrite) id (^createBlock)(void);
@property (nonatomic, assign, readwrite) NSUInteger capacity;
...

/*
 The instances you add, get and create should all be of this class or subclass
 */
- (instancetype)initWithClass:(Class)aClass;

/*
 Create an instance using `createBlock`
 */
- (id)create;

/*
 Add instance to the pool.
 It will immediately be accsible with `getLast` or `takeLast`
 */
- (BOOL)add:(id)instance;

/*
 Auto creates if none found - never returns nil
 */
- (id)takeFirstIn;
- (id)takeLastIn;
- (id)takeFirstInPreferablyMatching:(BOOL(^)(id instance))filter;
- (id)takeLastInPreferablyMatching:(BOOL(^)(id instance))filter;

/*
 Does not auto create and may return nil
 */
- (id)getFirstIn;
- (id)getLastIn;
- (id)getFirstInMatching:(BOOL(^)(id instance))filter;
- (id)getLastInMatching:(BOOL(^)(id instance))filter;
- (id)getFirstInPreferablyMatching:(BOOL(^)(id instance))filter;
- (id)getLastInPreferablyMatching:(BOOL(^)(id instance))filter;

/*
 Creates object using `createBlock`
 */
- (void)fill;
- (void)fillTo:(NSUInteger)mark;

/*
 Removes objects from the pool
 */
- (NSArray *)drain;
- (NSArray *)drainHalf;
- (NSArray *)drainTo:(NSUInteger)mark;

Terminology

If a and b were added to the pool in that order (a first) then firstIn refers a while lastIn refers to b.

Example

In most cases I recommend creating a simple facade. In this case IVYPagerReusePool owns an IVYPool and creates a clear and concise API.

@interface IVYPagerReusePool : NSObject

- (void)registerPageClass:(Class)pageClass forReuseIdentifier:(NSString *)reuseIdentifier;
- (Class)pageClassForReuseIdentifier:(NSString *)reuseIdentifier;

- (IVYArticlePage *)getAnyPageWithPath:(IVYPagerPath *)path;
- (IVYArticlePage *)getAnyPageWithIdentifier:(NSString *)identifier;
- (IVYArticlePage *)getAnyPageWithReuseIdentifier:(NSString *)reuseIdentifier;

- (NSArray <IVYArticlePage *> *)drainTo:(NSUInteger)mark;

- (BOOL)add:(IVYArticlePage *)page;

@end

Agens | Digital craftsmanship

Latest podspec

{
    "name": "IVYPool",
    "version": "0.2",
    "summary": "A thread safe pool factory for iOS. Store, get and create objects on demand.",
    "homepage": "https://github.com/hfossli/IVYPool",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "authors": {
        "Hu00e5vard Fossli": "[email protected]"
    },
    "source": {
        "git": "https://github.com/hfossli/IVYPool.git",
        "tag": "0.2"
    },
    "frameworks": "Foundation",
    "source_files": "Source/**/*.{h,m,mm,hpp,cpp,c}",
    "exclude_files": "Source/**/*Test.{h,m,mm,hpp,cpp,c}"
}

Pin It on Pinterest

Share This