Latest 1.3.0
Homepage https://github.com/yichizhang/YZLibrary
License MIT
Platforms ios 7.0, requires ARC
Frameworks Foundation, UIKit
Authors

This is the code that helped me in the past few years of iOS development.

Install

Simply use CocoaPods:

pod 'YZLibrary'

If you are using Swift, add this to your bridging header:

#import <YZLibrary/YZLibraryImportAll.h>

Documentation

You can view the documentation at http://www.yichizhang.info/YZLibrary/doc/

Examples

Random object from an array

NSArray *fruitArray = @[@"Apple", @"Banana", @"Cherry"];
NSString *fruitForToday = [fruitArray yz_randomObject];

Lazy Loading of Table View/ Collection View Cells

Files:
UICollectionViewCell+YZLibrary
UITableViewCell+YZLibrary

Set the NIB file name and the identifier to be the same as the class name of the cell.

For example, your custom Table View/ Collection View Cell class is ‘MyAwesomeCell’. Put the user interface in ‘MyAwesomeCell.xib’; change the cell identifier to ‘MyAwesomeCell’.

Then you can register the nib and load the cells VERY LAZILIY:

    override func viewDidLoad() {
        super.viewDidLoad()

        ...

        // Register cell classes
        MyAwesomeCell.yz_registerForCollectionView(self.collectionView)

        ...
    }

    override func collectionView(
        collectionView: UICollectionView,
        cellForItemAtIndexPath indexPath: NSIndexPath
        ) -> UICollectionViewCell {

        let cell =
        MyAwesomeCell.yz_dequeueFromCollectionView(
            collectionView,
            forIndexPath: indexPath
        )

        // Configure the cell
        ...

        return cell
    }

This may be a bad practice but can save you a lot of time.

You can provide custom NIB file name and your own identifier:


    let myAwesomeIdentifier = "AwesomeIdentifier"
    let myAwesomeNibName = "AwesomeNib"

    override func viewDidLoad() {
        super.viewDidLoad()

        ...

        // Register cell classes
        MyAwesomeCell.yz_registerForCollectionView(
            self.collectionView,
            withNibFileName: myAwesomeNibName,
            andReuseIdentifier: myAwesomeIdentifier
        )

        ...
    }

    override func collectionView(
        collectionView: UICollectionView,
        cellForItemAtIndexPath indexPath: NSIndexPath
        ) -> UICollectionViewCell {

        let cell =
        MyAwesomeCell.yz_dequeueFromCollectionView(
            collectionView,
            forIndexPath: indexPath,
            andReuseIdentifier: myAwesomeIdentifier
        )

        // Configure the cell
        ...

        return cell
    }

Latest podspec

{
    "name": "YZLibrary",
    "version": "1.3.0",
    "summary": "Some code that helped me in the past few years of iOS development.",
    "homepage": "https://github.com/yichizhang/YZLibrary",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Yichi Zhang": "[email protected]"
    },
    "source": {
        "git": "https://github.com/yichizhang/YZLibrary.git",
        "tag": "1.3.0"
    },
    "platforms": {
        "ios": "7.0"
    },
    "requires_arc": true,
    "source_files": "YZLibrary/*.{h,m}",
    "frameworks": [
        "Foundation",
        "UIKit"
    ]
}

Pin It on Pinterest

Share This