TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Mar 2016 |
Maintained by Yichi Zhang.
This is the code that helped me in the past few years of iOS development.
Simply use CocoaPods:
pod 'YZLibrary'
If you are using Swift, add this to your bridging header:
#import <YZLibrary/YZLibraryImportAll.h>
You can view the documentation at http://www.yichizhang.info/YZLibrary/doc/
NSArray *fruitArray = @[@"Apple", @"Banana", @"Cherry"];
NSString *fruitForToday = [fruitArray yz_randomObject];
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
}