Skip to content

Commit

Permalink
add ability to customize reuseIdentifiers. Preliminary Swift support
Browse files Browse the repository at this point in the history
  • Loading branch information
DenTelezhkin committed Jul 30, 2014
1 parent f623959 commit 5d426f6
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 10 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ profile
DerivedData
.idea/

Podfile.lock
Pods/
4 changes: 2 additions & 2 deletions DTCollectionViewManager.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'DTCollectionViewManager'
s.version = '2.4.0'
s.version = '2.5.0'
s.license = 'MIT'
s.summary = 'The most simple and robust way to manage UICollectionView.'
s.homepage = 'https://github.com/DenHeadless/DTCollectionViewManager'
Expand All @@ -12,5 +12,5 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '6.0'
s.ios.frameworks = 'UIKit', 'Foundation'
s.platform = :ios,'6.0'
s.dependency 'DTModelStorage' , '0.6.0'
s.dependency 'DTModelStorage' , '0.8.0'
end
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ - (id)model
return nil;
}

+(NSString *)reuseIdentifier
{
return NSStringFromClass(self);
}

@end
5 changes: 5 additions & 0 deletions DTCollectionViewManager/Convenience/DTCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ -(id)model
return nil;
}

+(NSString *)reuseIdentifier
{
return NSStringFromClass(self);
}

@end
21 changes: 17 additions & 4 deletions DTCollectionViewManager/DTCollectionViewFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ - (void)registerCellClass:(Class)cellClass forModelClass:(Class)modelClass
{
[[self.delegate collectionView] registerNib:[UINib nibWithNibName:cellClassString
bundle:nil]
forCellWithReuseIdentifier:cellClassString];
forCellWithReuseIdentifier:[self reuseIdentifierFromClass:cellClass]];
}
self.cellMappings[[self classStringForClass:modelClass]] = NSStringFromClass(cellClass);
}
Expand All @@ -90,7 +90,7 @@ - (void)registerSupplementaryClass:(Class)supplementaryClass
[[self.delegate collectionView] registerNib:[UINib nibWithNibName:supplementaryClassString
bundle:nil]
forSupplementaryViewOfKind:kind
withReuseIdentifier:supplementaryClassString];
withReuseIdentifier:[self reuseIdentifierFromClass:supplementaryClass]];
}
[self setSupplementaryClass:supplementaryClass
forKind:kind
Expand All @@ -100,7 +100,8 @@ - (void)registerSupplementaryClass:(Class)supplementaryClass
- (UICollectionViewCell <DTModelTransfer> *)cellForItem:(id)modelItem
atIndexPath:(NSIndexPath *)indexPath
{
NSString * reuseIdentifier = self.cellMappings[[self classStringForClass:[modelItem class]]];
NSString * classString = self.cellMappings[[self classStringForClass:[modelItem class]]];
NSString * reuseIdentifier = [self reuseIdentifierFromClass:NSClassFromString(classString)];
if (!reuseIdentifier)
{
return nil;
Expand All @@ -117,7 +118,8 @@ - (void)registerSupplementaryClass:(Class)supplementaryClass
forItem:(id)modelItem
atIndexPath:(NSIndexPath *)indexPath
{
NSString * reuseIdentifier = [self supplementaryClassForKind:kind modelClass:[modelItem class]];
NSString * classString = [self supplementaryClassForKind:kind modelClass:[modelItem class]];
NSString * reuseIdentifier = [self reuseIdentifierFromClass:NSClassFromString(classString)];
if (!reuseIdentifier)
{
return nil;
Expand All @@ -131,6 +133,17 @@ - (void)registerSupplementaryClass:(Class)supplementaryClass
}
}

-(NSString *)reuseIdentifierFromClass:(Class)klass
{
NSString * reuseIdentifier = NSStringFromClass(klass);

if ([klass respondsToSelector:@selector(reuseIdentifier)])
{
reuseIdentifier = [klass reuseIdentifier];
}
return reuseIdentifier;
}

- (NSString *)classStringForClass:(Class)class
{
NSString * classString = NSStringFromClass(class);
Expand Down
3 changes: 1 addition & 2 deletions Example/CedarUnitTests/CedarUnitTests-Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <Cedar-iOS/Cedar-iOS.h>
#import <Cedar-iOS/SpecHelper.h>
#import <Cedar/Cedar-iOS.h>
#import "DTCollectionViewManager.h"
#import <AutoDescribe/NSObject+AutoDescribe.h>
#endif
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ xcodeproj 'DTCollectionViewManagerExample.xcodeproj'
inhibit_all_warnings!
platform :ios, 6.0

pod 'DTModelStorage', '0.6.0'
pod 'DTModelStorage', '0.8.0'
pod 'PlaceKit', '~> 1.0.0'

target :Tests do
Expand Down
35 changes: 35 additions & 0 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
PODS:
- AutoDescribe (1.0.0)
- Cedar (0.9.7)
- DTModelStorage (0.8.0):
- DTModelStorage/All
- DTModelStorage/All (0.8.0):
- DTModelStorage/CoreDataStorage
- DTModelStorage/MemoryStorage
- DTModelStorage/ModelTransfer
- DTModelStorage/Core (0.8.0)
- DTModelStorage/CoreDataStorage (0.8.0):
- DTModelStorage/Core
- DTModelStorage/MemoryStorage (0.8.0):
- DTModelStorage/Core
- DTModelStorage/ModelTransfer (0.8.0)
- OCMock (2.2.4)
- PlaceKit (1.0.0):
- PlaceKit/Core
- PlaceKit/Core (1.0.0)

DEPENDENCIES:
- AutoDescribe
- Cedar
- DTModelStorage (= 0.8.0)
- OCMock (~> 2.2.1)
- PlaceKit (~> 1.0.0)

SPEC CHECKSUMS:
AutoDescribe: ef4ac47c8593c58ab852506368f61d3820a24ad5
Cedar: d704a464f628b39ce763d49f42b5510a9e0b03b9
DTModelStorage: 84b63252b63132c14238283d5de67aebe464694c
OCMock: 6db79185520e24f9f299548f2b8b07e41d881bd5
PlaceKit: bf5a00a4abada01dd8dc8f822987571a99263449

COCOAPODS: 0.33.1

0 comments on commit 5d426f6

Please sign in to comment.