2018-04-23 16:27:43 +00:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< title > Generating your models Reference< / title >
< link rel = "stylesheet" type = "text/css" href = "css/jazzy.css" / >
< link rel = "stylesheet" type = "text/css" href = "css/highlight.css" / >
< meta charset = 'utf-8' >
< script src = "js/jquery.min.js" defer > < / script >
< script src = "js/jazzy.js" defer > < / script >
< / head >
< body >
< a title = "Generating your models Reference" > < / a >
< header >
< div class = "content-wrapper" >
< p > < a href = "index.html" > IGListKit Docs< / a > (98% documented)< / p >
< p class = "header-right" > < a href = "https://github.com/Instagram/IGListKit" > < img src = "img/gh.png" / > View on GitHub< / a > < / p >
< / div >
< / header >
< div class = "content-wrapper" >
< p id = "breadcrumbs" >
< a href = "index.html" > IGListKit Reference< / a >
< img id = "carat" src = "img/carat.png" / >
Generating your models Reference
< / p >
< / div >
< div class = "content-wrapper" >
< nav class = "sidebar" >
< ul class = "nav-groups" >
< li class = "nav-group-name" >
< a href = "Guides.html" > Guides< / a >
< ul class = "nav-group-tasks" >
< li class = "nav-group-task" >
< a href = "best-practices-and-faq.html" > Best Practices and FAQ< / a >
< / li >
< li class = "nav-group-task" >
< a href = "generating-your-models.html" > Generating your models< / a >
< / li >
< li class = "nav-group-task" >
< a href = "getting-started.html" > Getting Started< / a >
< / li >
< li class = "nav-group-task" >
< a href = "iglistdiffable-and-equality.html" > IGListDiffable and Equality< / a >
< / li >
< li class = "nav-group-task" >
< a href = "installation.html" > Installation< / a >
< / li >
< li class = "nav-group-task" >
< a href = "migration.html" > Migration< / a >
< / li >
< li class = "nav-group-task" >
< a href = "modeling-and-binding.html" > Modeling and Binding< / a >
< / li >
< li class = "nav-group-task" >
< a href = "vision.html" > VISION< / a >
< / li >
< li class = "nav-group-task" >
< a href = "working-with-core-data.html" > Working with Core Data< / a >
< / li >
< li class = "nav-group-task" >
< a href = "working-with-uicollectionview.html" > Working with UICollectionView< / a >
< / li >
< / ul >
< / li >
< li class = "nav-group-name" >
< a href = "Classes.html" > Classes< / a >
< ul class = "nav-group-tasks" >
< li class = "nav-group-task" >
< a href = "Classes/IGListAdapter.html" > IGListAdapter< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListAdapterUpdater.html" > IGListAdapterUpdater< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListBatchUpdateData.html" > IGListBatchUpdateData< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListBindingSectionController.html" > IGListBindingSectionController< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListCollectionView.html" > IGListCollectionView< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListCollectionViewLayout.html" > IGListCollectionViewLayout< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListGenericSectionController.html" > IGListGenericSectionController< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListIndexPathResult.html" > IGListIndexPathResult< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListIndexSetResult.html" > IGListIndexSetResult< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListMoveIndex.html" > IGListMoveIndex< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListMoveIndexPath.html" > IGListMoveIndexPath< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes.html#/c:objc(cs)IGListReloadDataUpdater" > IGListReloadDataUpdater< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListSectionController.html" > IGListSectionController< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListSingleSectionController.html" > IGListSingleSectionController< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Classes/IGListStackedSectionController.html" > IGListStackedSectionController< / a >
< / li >
< / ul >
< / li >
< li class = "nav-group-name" >
< a href = "Constants.html" > Constants< / a >
< ul class = "nav-group-tasks" >
< li class = "nav-group-task" >
< a href = "Constants.html#/c:@IGListKitVersionNumber" > IGListKitVersionNumber< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Constants.html#/c:@IGListKitVersionString" > IGListKitVersionString< / a >
< / li >
< / ul >
< / li >
< li class = "nav-group-name" >
< a href = "Enums.html" > Enumerations< / a >
< ul class = "nav-group-tasks" >
< li class = "nav-group-task" >
< a href = "Enums/IGListAdapterUpdateType.html" > IGListAdapterUpdateType< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Enums/IGListDiffOption.html" > IGListDiffOption< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Enums/IGListExperiment.html" > IGListExperiment< / a >
< / li >
< / ul >
< / li >
< li class = "nav-group-name" >
< a href = "Protocols.html" > Protocols< / a >
< ul class = "nav-group-tasks" >
< li class = "nav-group-task" >
< a href = "Protocols/IGListAdapterDataSource.html" > IGListAdapterDataSource< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListAdapterDelegate.html" > IGListAdapterDelegate< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListAdapterMoveDelegate.html" > IGListAdapterMoveDelegate< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListAdapterUpdateListener.html" > IGListAdapterUpdateListener< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListAdapterUpdaterDelegate.html" > IGListAdapterUpdaterDelegate< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListBatchContext.html" > IGListBatchContext< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListBindable.html" > IGListBindable< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListBindingSectionControllerDataSource.html" > IGListBindingSectionControllerDataSource< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListBindingSectionControllerSelectionDelegate.html" > IGListBindingSectionControllerSelectionDelegate< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListCollectionContext.html" > IGListCollectionContext< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListCollectionViewDelegateLayout.html" > IGListCollectionViewDelegateLayout< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListDiffable.html" > IGListDiffable< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListDisplayDelegate.html" > IGListDisplayDelegate< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListScrollDelegate.html" > IGListScrollDelegate< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListSingleSectionControllerDelegate.html" > IGListSingleSectionControllerDelegate< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListSupplementaryViewSource.html" > IGListSupplementaryViewSource< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListTransitionDelegate.html" > IGListTransitionDelegate< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListUpdatingDelegate.html" > IGListUpdatingDelegate< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Protocols/IGListWorkingRangeDelegate.html" > IGListWorkingRangeDelegate< / a >
< / li >
< / ul >
< / li >
< li class = "nav-group-name" >
< a href = "Type Definitions.html" > Type Definitions< / a >
< ul class = "nav-group-tasks" >
< li class = "nav-group-task" >
< a href = "Type Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListItemUpdateBlock" > IGListItemUpdateBlock< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Type Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListObjectTransitionBlock" > IGListObjectTransitionBlock< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Type Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListReloadUpdateBlock" > IGListReloadUpdateBlock< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Type Definitions.html#/c:IGListSingleSectionController.h@T@IGListSingleSectionCellConfigureBlock" > IGListSingleSectionCellConfigureBlock< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Type Definitions.html#/c:IGListSingleSectionController.h@T@IGListSingleSectionCellSizeBlock" > IGListSingleSectionCellSizeBlock< / a >
< / li >
2018-05-01 23:54:35 +00:00
< li class = "nav-group-task" >
< a href = "Type Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListToObjectBlock" > IGListToObjectBlock< / a >
< / li >
2018-04-23 16:27:43 +00:00
< li class = "nav-group-task" >
< a href = "Type Definitions.html#/c:IGListAdapter.h@T@IGListUpdaterCompletion" > IGListUpdaterCompletion< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Type Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListUpdatingCompletion" > IGListUpdatingCompletion< / a >
< / li >
< / ul >
< / li >
< li class = "nav-group-name" >
< a href = "Functions.html" > Functions< / a >
< ul class = "nav-group-tasks" >
< li class = "nav-group-task" >
< a href = "Functions.html#/c:@F@IGListDiff" > IGListDiff< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Functions.html#/c:@F@IGListDiffExperiment" > IGListDiffExperiment< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Functions.html#/c:@F@IGListDiffPaths" > IGListDiffPaths< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Functions.html#/c:@F@IGListDiffPathsExperiment" > IGListDiffPathsExperiment< / a >
< / li >
< li class = "nav-group-task" >
< a href = "Functions.html#/c:IGListExperiments.h@F@IGListExperimentEnabled" > IGListExperimentEnabled< / a >
< / li >
< / ul >
< / li >
< / ul >
< / nav >
< article class = "main-content" >
< section >
< section class = "section" >
< h1 id = 'generating-your-iglistdiffable-models' class = 'heading' > Generating your IGListDiffable models< / h1 >
< p > With the < code > < a href = "Protocols/IGListDiffable.html" > IGListDiffable< / a > < / code > plugin for < a href = "https://github.com/facebook/remodel" > remodel by facebook< / a > , you can automatically generate models conforming to the < code > < a href = "Protocols/IGListDiffable.html" > IGListDiffable< / a > < / code > .< / p >
< p > This will automatically implement < code > hash< / code > , < code > isEqual:< / code > and < code > description< / code > , as well as < code > diffIdentifier< / code > and < code > isEqualToDiffableObject:< / code > for you. Remodel is also capable to generate additional code, like conforming to < code > NSCoding< / code > or additional Builder classes for your model object. It will make creating and updating models much easier, faster and safer.< / p >
< p > In < code > /remodel-plugin< / code > , you can find the source files to build the < code > < a href = "Protocols/IGListDiffable.html" > IGListDiffable< / a > < / code > plugin locally.< / p >
< h2 id = 'installation' class = 'heading' > Installation< / h2 >
< h3 id = '1-remodel-installation' class = 'heading' > 1. Remodel installation< / h3 >
< p > Please follow the < a href = "https://github.com/facebook/remodel" > installation instructions< / a > in the main remodel repository.< / p >
< p > tl;dr: Either clone the original repository, or use an npm installation. In the latter case you can run < code > which remodel-gen< / code > to find out the path of your installation.< / p >
< h3 id = '2-plugin-installation' class = 'heading' > 2. Plugin installation< / h3 >
< p > Copy the following files & folders within < code > /remodel-plugin< / code > into your local remodel checkout:< / p >
< ul >
< li > < code > /src/plugins/iglistdiffable.ts< / code > - the actual plugin< / li >
< li > < code > /src/__tests__/plugins/iglistdiffable-test.ts< / code > - unit tests< / li >
< li > < code > /features/iglistdiffable.feature< / code > - integration tests< / li >
< / ul >
< p > And then register the new plugin with the system:< / p >
< ul >
< li > Edit < code > /remodel/src/value-object-default-config.ts< / code > and add < code > iglistdiffable< / code > to the list of basePlugins:< / li >
< / ul >
< pre class = "highlight plaintext" > < code > // value-object-default-config.ts
basePlugins: List.of(
'assert-nullability',
'assume-nonnull',
'builder',
'coding',
'copying',
'description',
'equality',
'fetch-status',
'immutable-properties',
'init-new-unavailable',
'use-cpp',
'iglistdiffable'
)
< / code > < / pre >
< h3 id = '3-build-plugin' class = 'heading' > 3. Build plugin:< / h3 >
< p > Once you copied them over and registered the plugin, you have to compile the typescript files into javascript. Do do so run this command from the remodel directory:< / p >
< ul >
< li > < code > ./bin/build< / code > < / li >
< / ul >
< h3 id = '4-run-tests-optional' class = 'heading' > 4. Run tests (optional)< / h3 >
< p > To run the unit/integration tests, you can run the following commands:< / p >
< ul >
< li > < code > ./bin/runUnitTests< / code > < / li >
< li > < code > ./bin/runAcceptanceTests< / code > < / li >
< / ul >
< p > This is especially useful if you plan to change/extend the plugin in any way.< / p >
< h3 id = '5-use-the-plugin' class = 'heading' > 5. Use the plugin< / h3 >
< p > Now you are ready to generate your < code > < a href = "Protocols/IGListDiffable.html" > IGListDiffable< / a > < / code > conforming models! To generate a model, create a new < code > .value< / code > file. Here’ s an example:< / p >
< pre class = "highlight plaintext" > < code > // PersonModel.value
PersonModel includes(IGListDiffable) {
NSString *firstName
NSString *lastName
%diffIdentifier
NSString *uniqueId
}
< / code > < / pre >
< p > To generate your Objective-C models, run the generation tool like this:< / p >
< p > < code > ./bin/generate path/to/your/PersonModel.value< / code > < / p >
< p > This will generate the following Objective-C files in the same directory:< / p >
< pre class = "highlight plaintext" > < code > // PersonModel.h
@interface PersonModel : NSObject < IGListDiffable, NSCopying>
@property (nonatomic, readonly, copy) NSString *firstName;
@property (nonatomic, readonly, copy) NSString *lastName;
@property (nonatomic, readonly, copy) NSString *uniqueId;
- (instancetype)initWithFirstName:(NSString *)firstName lastName:(NSString *)lastName uniqueId:(NSString *)uniqueId;
@end
< / code > < / pre >
< p > and< / p >
< pre class = "highlight plaintext" > < code > // PersonModel.m
@implementation PersonModel
- (instancetype)initWithFirstName:(NSString *)firstName lastName:(NSString *)lastName uniqueId:(NSString *)uniqueId
{
if ((self = [super init])) {
_firstName = [firstName copy];
_lastName = [lastName copy];
_uniqueId = [uniqueId copy];
}
return self;
}
- (id< NSObject> )diffIdentifier
{
return _uniqueId;
}
- (BOOL)isEqualToDiffableObject:(nullable id)object
{
return [self isEqual:object];
}
- (BOOL)isEqual:(PersonModel *)object
{
if (self == object) {
return YES;
} else if (self == nil || object == nil || ![object isKindOfClass:[self class]]) {
return NO;
}
return
(_firstName == object-> _firstName ? YES : [_firstName isEqual:object-> _firstName]) & &
(_lastName == object-> _lastName ? YES : [_lastName isEqual:object-> _lastName]) & &
(_uniqueId == object-> _uniqueId ? YES : [_uniqueId isEqual:object-> _uniqueId]);
}
- (id)copyWithZone:(nullable NSZone *)zone
{
return self;
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ - \n\t firstName: %@; \n\t lastName: %@; \n\t uniqueId: %@; \n", [super description], _firstName, _lastName, _uniqueId];
}
- (NSUInteger)hash
{
NSUInteger subhashes[] = {[_firstName hash], [_lastName hash], [_uniqueId hash]};
NSUInteger result = subhashes[0];
for (int ii = 1; ii < 3; ++ii) {
unsigned long long base = (((unsigned long long)result) < < 32 | subhashes[ii]);
base = (~base) + (base < < 18);
base ^= (base > > 31);
base *= 21;
base ^= (base > > 11);
base += (base < < 6);
base ^= (base > > 22);
result = base;
}
return result;
}
@end
< / code > < / pre >
< h2 id = 'documentation' class = 'heading' > Documentation< / h2 >
< p > Please see the main remodel repository for < a href = "https://github.com/facebook/remodel" > additional documentation< / a > < / p >
< / section >
< / section >
< section id = "footer" >
2018-05-01 23:54:35 +00:00
< p > © 2018 < a class = "link" href = "https://twitter.com/fbOpenSource" target = "_blank" rel = "external" > Instagram< / a > . All rights reserved. (Last updated: 2018-05-01)< / p >
2018-04-23 16:27:43 +00:00
< p > Generated by < a class = "link" href = "https://github.com/realm/jazzy" target = "_blank" rel = "external" > jazzy ♪♫ v0.9.1< / a > , a < a class = "link" href = "http://realm.io" target = "_blank" rel = "external" > Realm< / a > project.< / p >
< / section >
< / article >
< / div >
< / body >
< / div >
< / html >