Skip to content

Commit

Permalink
Add lightweight generics to the core classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Moose committed Sep 30, 2015
1 parent 6d38297 commit 000f71a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 20 deletions.
16 changes: 14 additions & 2 deletions Examples/Settings/Settings/en.lproj/MainStoryboard.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6751" systemVersion="14D130a" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="392-mi-Unb">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="392-mi-Unb">
<dependencies>
<deployment identifier="iOS"/>
<development version="6000" identifier="xcode"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
Expand All @@ -21,8 +22,10 @@
</view>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="Sound" id="4dJ-3X-IXH" customClass="TLDynamicHeightCell">
<rect key="frame" x="0.0" y="42" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="4dJ-3X-IXH" id="MQI-M5-x5W">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" tag="1" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Hze-ZX-sTJ">
Expand Down Expand Up @@ -58,8 +61,10 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="Volume" rowHeight="80" id="Gqe-57-2Hy" customClass="TLDynamicHeightCell">
<rect key="frame" x="0.0" y="86" width="600" height="80"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Gqe-57-2Hy" id="gcC-Go-b3y">
<rect key="frame" x="0.0" y="0.0" width="600" height="79.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" tag="1" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Volume Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vwP-u2-sXS">
Expand Down Expand Up @@ -95,11 +100,14 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="DifficultyOption" textLabel="c1u-v5-oXD" style="IBUITableViewCellStyleDefault" id="Y32-Mf-4hq">
<rect key="frame" x="0.0" y="166" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Y32-Mf-4hq" id="JDH-tr-CQr">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Difficulty Option" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="c1u-v5-oXD">
<rect key="frame" x="15" y="0.0" width="570" height="43.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
Expand All @@ -109,17 +117,21 @@
</tableViewCellContentView>
</tableViewCell>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Difficulty" textLabel="TV9-C0-7na" detailTextLabel="knh-cF-GWr" style="IBUITableViewCellStyleValue1" id="WGi-XX-kcB">
<rect key="frame" x="0.0" y="210" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="WGi-XX-kcB" id="fmS-jG-wEH">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Difficulty Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="TV9-C0-7na">
<rect key="frame" x="15" y="12" width="108.5" height="19.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Detail" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="knh-cF-GWr">
<rect key="frame" x="543.5" y="12" width="41.5" height="19.5"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" red="0.5568627451" green="0.5568627451" blue="0.57647058819999997" alpha="1" colorSpace="calibratedRGB"/>
Expand Down
15 changes: 7 additions & 8 deletions TLIndexPathTools.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "TLIndexPathTools"
s.version = "0.4.0"
s.version = "0.5.0"
s.summary = "TLIndexPathTools is a small set of classes that can greatly simplify your table and collection views."
s.description = <<-DESC
TLIndexPathTools is a small set of classes that can greatly simplify your table and collection views. Here are some of the awesome things TLIndexPathTools does:
Expand All @@ -11,20 +11,19 @@ Pod::Spec.new do |s|
* Provide a simpler alternative to Core Data NSFetchedResultsController
* Provide base table view and collection view classes with advanced features
0.4.0
* Add swift nullability annotations to the core classes:
0.5.0
* Add lightweight generics to the core classes:
TLIndexPathDataModel
TLIndexPathUpdates
TLIndexPathController
TLIndexPathItem
* #56 Add optional modification comparitor block to TLIndexPathUpdates
DESC
s.homepage = "http://tlindexpathtools.com"
s.license = { :type => "MIT" }
s.author = { "wtmoose" => "[email protected]" }
s.source = { :git => "https://github.com/wtmoose/TLIndexPathTools.git", :tag => '0.4.0' }
s.platform = :ios, '6.0'
s.ios.deployment_target = '6.0'
s.source = { :git => "https://github.com/wtmoose/TLIndexPathTools.git", :tag => '0.5.0' }
s.platform = :ios, '7.0'
s.ios.deployment_target = '7.0'
s.source_files = 'TLIndexPathTools/**/*.{h,m}'
s.frameworks = 'UIKit', 'QuartzCore', 'CoreData', 'Foundation'
s.requires_arc = true
Expand Down
1 change: 1 addition & 0 deletions TLIndexPathTools.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@
B145DAB1179EE94300CF270E /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0610;
ORGANIZATIONNAME = "Tractable Labs";
TargetAttributes = {
Expand Down
9 changes: 5 additions & 4 deletions TLIndexPathTools/Data Model/TLIndexPathDataModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
NS_ASSUME_NONNULL_BEGIN

extern NSString * TLIndexPathDataModelNilSectionName;
@class TLIndexPathSectionInfo;

@interface TLIndexPathDataModel : NSObject

Expand Down Expand Up @@ -191,7 +192,7 @@ extern NSString * TLIndexPathDataModelNilSectionName;
@param identifierKeyPath the item key path to use for identification. Specifying `nil`
will result in the default object identification rules being used.
*/
- (id)initWithSectionInfos:(NSArray *)sectionInfos identifierKeyPath:(NSString * __nullable)identifierKeyPath;
- (id)initWithSectionInfos:(NSArray<TLIndexPathSectionInfo *> *)sectionInfos identifierKeyPath:(NSString * __nullable)identifierKeyPath;

#pragma mark - Data model configuration
/** @name Data model configuration */
Expand Down Expand Up @@ -236,13 +237,13 @@ extern NSString * TLIndexPathDataModelNilSectionName;
any explicit sections, this array will contain the single name `TLIndexPathDataModelNilSectionName`.
Note that section names are unique. See Section Names.
*/
@property (strong, nonatomic, readonly) NSArray *sectionNames;
@property (strong, nonatomic, readonly) NSArray<NSString *> *sectionNames;

/**
The array of `TLIndexPathSectionInfo` objects organizing the data into sections.
`TLIndexPathSectionInfo` is an implementation of the `NSFetchedResultsSectionInfo` protocol.
*/
@property (strong, nonatomic, readonly) NSArray *sections;
@property (strong, nonatomic, readonly) NSArray<TLIndexPathSectionInfo *> *sections;

/**
An array containing all items.
Expand All @@ -252,7 +253,7 @@ extern NSString * TLIndexPathDataModelNilSectionName;
/**
An array containing all index paths.
*/
@property (strong, nonatomic, readonly) NSArray *indexPaths;
@property (strong, nonatomic, readonly) NSArray<NSIndexPath *> *indexPaths;

/**
The number of rows in the specified section. Returns `NSNotFound` for an invalid section.
Expand Down
4 changes: 2 additions & 2 deletions TLIndexPathTools/Data Model/TLIndexPathDataModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ - (id)initWithSectionInfos:(NSArray *)sectionInfos identifierKeyPath:(NSString *
return self;
}

- (id)initWithSectionInfos:(NSArray *)sectionInfos sectionNameBlock:(NSString *(^)(id))sectionNameBlock identifierBlock:(id (^)(id))identifierBlock
- (id)initWithSectionInfos:(NSArray<TLIndexPathSectionInfo *> *)sectionInfos sectionNameBlock:(NSString *(^)(id))sectionNameBlock identifierBlock:(id (^)(id))identifierBlock
{
//if there are no sections, insert an empty section to keep UICollectionView
//happy. If we don't do this, UICollectionView will crash on the first
Expand Down Expand Up @@ -242,7 +242,7 @@ - (NSString *)sectionNameForSection:(NSInteger)section

- (NSInteger)sectionForSectionName:(NSString *)sectionName
{
id<NSFetchedResultsSectionInfo>sectionInfo = [self.sectionInfosBySectionName objectForKey:sectionName];
TLIndexPathSectionInfo *sectionInfo = [self.sectionInfosBySectionName objectForKey:sectionName];
return sectionInfo ? [self.sections indexOfObject:sectionInfo] : NSNotFound;
}

Expand Down
6 changes: 3 additions & 3 deletions TLIndexPathTools/Data Model/TLIndexPathUpdates.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (strong, readonly, nonatomic, nullable) TLIndexPathDataModel *oldDataModel;
@property (strong, readonly, nonatomic, nullable) TLIndexPathDataModel *updatedDataModel;
@property (readonly, nonatomic) BOOL hasChanges;
@property (copy, readonly, nonatomic) NSArray *insertedSectionNames;
@property (copy, readonly, nonatomic) NSArray *deletedSectionNames;
@property (copy, readonly, nonatomic) NSArray *movedSectionNames;
@property (copy, readonly, nonatomic) NSArray<NSString *> *insertedSectionNames;
@property (copy, readonly, nonatomic) NSArray<NSString *> *deletedSectionNames;
@property (copy, readonly, nonatomic) NSArray<NSString *> *movedSectionNames;
@property (copy, readonly, nonatomic) NSArray *insertedItems;
@property (copy, readonly, nonatomic) NSArray *deletedItems;
@property (copy, readonly, nonatomic) NSArray *movedItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "UITableViewController+ScrollOptimizer.h"
#import "TLIndexPathSectionInfo.h"

@implementation UITableViewController (ScrollOptimizer)

Expand Down Expand Up @@ -41,7 +42,7 @@ - (void)optimizeScrollPositionForSection:(NSInteger)section headerView:(UIView *
}

// Iterate over rows to find out how many can be made visible
id<NSFetchedResultsSectionInfo>sectionInfo = dataModel.sections[section];
TLIndexPathSectionInfo *sectionInfo = dataModel.sections[section];
for (id item in sectionInfo.objects) {
NSIndexPath *indexPath = [dataModel indexPathForItem:item];
offsetBelowTopToMakeVisible += [self tableView:self.tableView heightForRowAtIndexPath:indexPath];
Expand Down

0 comments on commit 000f71a

Please sign in to comment.