diff --git a/.travis.yml b/.travis.yml index 02e669e..bd8f41b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,5 @@ language: objective-c cache: cocoapods before_install: gem install xcpretty cocoapods obcd slather -N podfile: Podfile -script: xcodebuild -workspace Demo.xcworkspace -scheme Tests -sdk iphonesimulator build test GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES clean test | xcpretty -c && exit ${PIPESTATUS[0]} +script: xcodebuild -workspace Demo.xcworkspace -scheme Tests -sdk iphonesimulator build test -destination 'platform=iOS Simulator,name=iPhone 6' GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES GCC_GENERATE_TEST_COVERAGE_FILES=YES clean test | xcpretty -c && exit ${PIPESTATUS[0]} after_success: slather diff --git a/CollectionObjC/CollectionCell.h b/CollectionObjC/CollectionCell.h deleted file mode 100755 index 58e9097..0000000 --- a/CollectionObjC/CollectionCell.h +++ /dev/null @@ -1,9 +0,0 @@ -@import UIKit; - -extern NSString * const CollectionCellIdentifier; - -@interface CollectionCell : UICollectionViewCell - -- (void)updateWithText:(NSString *)text; - -@end diff --git a/CollectionObjC/CollectionCell.m b/CollectionObjC/CollectionCell.m deleted file mode 100755 index 3c67edc..0000000 --- a/CollectionObjC/CollectionCell.m +++ /dev/null @@ -1,37 +0,0 @@ -#import "CollectionCell.h" - -NSString * const CollectionCellIdentifier = @"CollectionCellIdentifier"; - -@interface CollectionCell () - -@property (nonatomic) UILabel *textLabel; - -@end - -@implementation CollectionCell - -- (UILabel *)textLabel { - if (!_textLabel) { - _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; - _textLabel.textAlignment = NSTextAlignmentCenter; - } - - return _textLabel; -} - -- (instancetype)initWithFrame:(CGRect)frame { - self = [super initWithFrame:frame]; - if (self) { - [self.contentView addSubview:self.textLabel]; - self.contentView.layer.borderWidth = 1.0; - self.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor; - } - - return self; -} - -- (void)updateWithText:(NSString *)text { - self.textLabel.text = text; -} - -@end diff --git a/CollectionObjC/ViewController.m b/CollectionObjC/ViewController.m index f9dab20..d93b8fe 100755 --- a/CollectionObjC/ViewController.m +++ b/CollectionObjC/ViewController.m @@ -5,7 +5,7 @@ @import CoreData; #import "FooterExampleView.h" -#import "CollectionCell.h" +#import "CollectionObjC-Swift.h" @interface ViewController () @@ -33,13 +33,13 @@ - (DATASource *)dataSource { request.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"firstLetterOfName" ascending:YES], [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]]; _dataSource = [[DATASource alloc] initWithCollectionView:self.collectionView - cellIdentifier:CollectionCellIdentifier + cellIdentifier:[CollectionCell Identifier] fetchRequest:request mainContext:self.dataStack.mainContext sectionName:@"firstLetterOfName" configuration:^(UICollectionViewCell * _Nonnull cell, NSManagedObject * _Nonnull item, NSIndexPath * _Nonnull indexPath) { CollectionCell *collectionCell = (CollectionCell *)cell; - [collectionCell updateWithText:[item valueForKey:@"name"]]; + collectionCell.textLabel.text = [item valueForKey:@"name"]; }]; _dataSource.delegate = self; @@ -49,7 +49,7 @@ - (DATASource *)dataSource { - (void)viewDidLoad { [super viewDidLoad]; - [self.collectionView registerClass:[CollectionCell class] forCellWithReuseIdentifier:CollectionCellIdentifier]; + [self.collectionView registerClass:[CollectionCell class] forCellWithReuseIdentifier:[CollectionCell Identifier]]; UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAction)]; diff --git a/CollectionSwift/CollectionController.swift b/CollectionSwift/CollectionController.swift index 051a2b0..425e094 100644 --- a/CollectionSwift/CollectionController.swift +++ b/CollectionSwift/CollectionController.swift @@ -5,10 +5,10 @@ import DATASource import CoreData class CollectionController: UICollectionViewController { - var dataStack: DATAStack? + unowned var dataStack: DATAStack lazy var dataSource: DATASource = { - guard let collectionView = self.collectionView, mainContext = self.dataStack?.mainContext else { fatalError("CollectionView is nil") } + guard let collectionView = self.collectionView else { fatalError("CollectionView is nil") } let request: NSFetchRequest = NSFetchRequest(entityName: "User") request.sortDescriptors = [ @@ -16,7 +16,7 @@ class CollectionController: UICollectionViewController { NSSortDescriptor(key: "firstLetterOfName", ascending: true) ] - let dataSource = DATASource(collectionView: collectionView, cellIdentifier: CollectionCell.Identifier, fetchRequest: request, mainContext: mainContext, sectionName: "firstLetterOfName", configuration: { cell, item, indexPath in + let dataSource = DATASource(collectionView: collectionView, cellIdentifier: CollectionCell.Identifier, fetchRequest: request, mainContext: self.dataStack.mainContext, sectionName: "firstLetterOfName", configuration: { cell, item, indexPath in let collectionCell = cell as! CollectionCell collectionCell.textLabel.text = item.valueForKey("name") as? String }) @@ -25,9 +25,9 @@ class CollectionController: UICollectionViewController { }() init(layout: UICollectionViewLayout, dataStack: DATAStack) { - super.init(collectionViewLayout: layout) - self.dataStack = dataStack + + super.init(collectionViewLayout: layout) } required init?(coder aDecoder: NSCoder) { @@ -48,7 +48,7 @@ class CollectionController: UICollectionViewController { } func saveAction() { - self.dataStack?.performInNewBackgroundContext { backgroundContext in + self.dataStack.performInNewBackgroundContext { backgroundContext in if let entity = NSEntityDescription.entityForName("User", inManagedObjectContext: backgroundContext) { let user = NSManagedObject(entity: entity, insertIntoManagedObjectContext: backgroundContext) @@ -65,7 +65,7 @@ class CollectionController: UICollectionViewController { fatalError() } - self.dataStack?.persistWithCompletion({ }) + self.dataStack.persistWithCompletion({ }) } else { print("Oh no") } @@ -91,17 +91,17 @@ extension CollectionController { guard let object = self.dataSource.objectAtIndexPath(indexPath) else { return } if let name = object.valueForKey("name") as? String where name.characters.first == "A" { - self.dataStack?.performInNewBackgroundContext({ backgroundContext in + self.dataStack.performInNewBackgroundContext({ backgroundContext in let backgroundObject = backgroundContext.objectWithID(object.objectID) backgroundObject.setValue(name + "+", forKey: "name") try! backgroundContext.save() }) } else { - self.dataStack?.performInNewBackgroundContext({ backgroundContext in + self.dataStack.performInNewBackgroundContext({ backgroundContext in let backgroundObject = backgroundContext.objectWithID(object.objectID) backgroundContext.deleteObject(backgroundObject) try! backgroundContext.save() }) } } -} \ No newline at end of file +} diff --git a/Demo.xcodeproj/project.pbxproj b/Demo.xcodeproj/project.pbxproj index 6e15238..1aad371 100644 --- a/Demo.xcodeproj/project.pbxproj +++ b/Demo.xcodeproj/project.pbxproj @@ -9,24 +9,38 @@ /* Begin PBXBuildFile section */ 0299322E8667C83ED0DEA919 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B49785EF9F4AAF152E01ABC3 /* Pods.framework */; }; 141D2EE41BE021500028F879 /* CustomCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 141D2EE31BE021500028F879 /* CustomCell.swift */; }; - 1458F8151C3AA548000652AF /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1458F8141C3AA548000652AF /* LoadingView.swift */; }; 146205831C3AB0E400D78FC5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 146205821C3AB0E400D78FC5 /* AppDelegate.swift */; }; 146205851C3AB0E400D78FC5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 146205841C3AB0E400D78FC5 /* Assets.xcassets */; }; 146205881C3AB0E400D78FC5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 146205861C3AB0E400D78FC5 /* LaunchScreen.storyboard */; }; - 1462058D1C3AB0E900D78FC5 /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 148C57701C0EBCB500546AEF /* DataModel.xcdatamodeld */; }; - 146205901C3AB10500D78FC5 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1462058E1C3AB10500D78FC5 /* LoadingView.swift */; }; - 148C57721C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 148C57701C0EBCB500546AEF /* DataModel.xcdatamodeld */; }; - 148C57731C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 148C57701C0EBCB500546AEF /* DataModel.xcdatamodeld */; }; - 148C57741C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 148C57701C0EBCB500546AEF /* DataModel.xcdatamodeld */; }; - 148C57751C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 148C57701C0EBCB500546AEF /* DataModel.xcdatamodeld */; }; - 148C57761C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 148C57701C0EBCB500546AEF /* DataModel.xcdatamodeld */; }; - 148C57771C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 148C57701C0EBCB500546AEF /* DataModel.xcdatamodeld */; }; + 1498B6091C3BC9E80066FAC8 /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6051C3BC9E80066FAC8 /* CollectionCell.swift */; }; + 1498B60A1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6051C3BC9E80066FAC8 /* CollectionCell.swift */; }; + 1498B60B1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6051C3BC9E80066FAC8 /* CollectionCell.swift */; }; + 1498B60C1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6051C3BC9E80066FAC8 /* CollectionCell.swift */; }; + 1498B60D1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6051C3BC9E80066FAC8 /* CollectionCell.swift */; }; + 1498B60E1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6051C3BC9E80066FAC8 /* CollectionCell.swift */; }; + 1498B60F1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6051C3BC9E80066FAC8 /* CollectionCell.swift */; }; + 1498B6101C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6061C3BC9E80066FAC8 /* DataModel.xcdatamodeld */; }; + 1498B6111C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6061C3BC9E80066FAC8 /* DataModel.xcdatamodeld */; }; + 1498B6121C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6061C3BC9E80066FAC8 /* DataModel.xcdatamodeld */; }; + 1498B6131C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6061C3BC9E80066FAC8 /* DataModel.xcdatamodeld */; }; + 1498B6141C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6061C3BC9E80066FAC8 /* DataModel.xcdatamodeld */; }; + 1498B6151C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6061C3BC9E80066FAC8 /* DataModel.xcdatamodeld */; }; + 1498B6161C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6061C3BC9E80066FAC8 /* DataModel.xcdatamodeld */; }; + 1498B6171C3BC9E80066FAC8 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6081C3BC9E80066FAC8 /* LoadingView.swift */; }; + 1498B6181C3BC9E80066FAC8 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6081C3BC9E80066FAC8 /* LoadingView.swift */; }; + 1498B6191C3BC9E80066FAC8 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6081C3BC9E80066FAC8 /* LoadingView.swift */; }; + 1498B61A1C3BC9E80066FAC8 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6081C3BC9E80066FAC8 /* LoadingView.swift */; }; + 1498B61B1C3BC9E80066FAC8 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6081C3BC9E80066FAC8 /* LoadingView.swift */; }; + 1498B61C1C3BC9E80066FAC8 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6081C3BC9E80066FAC8 /* LoadingView.swift */; }; + 1498B61D1C3BC9E80066FAC8 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6081C3BC9E80066FAC8 /* LoadingView.swift */; }; 149AF1931C0EB9EF00BA0907 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 149AF1921C0EB9EF00BA0907 /* AppDelegate.swift */; }; 149AF1981C0EB9EF00BA0907 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 149AF1971C0EB9EF00BA0907 /* Assets.xcassets */; }; 149AF19B1C0EB9EF00BA0907 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 149AF1991C0EB9EF00BA0907 /* LaunchScreen.storyboard */; }; 149AF1A11C0EBA0700BA0907 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 149AF1A01C0EBA0700BA0907 /* ViewController.swift */; }; 14A139B41AEFC72B00AD732F /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14A139B31AEFC72B00AD732F /* Tests.swift */; }; - 14AEBDA51C3A8F4F00A26353 /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 148C57701C0EBCB500546AEF /* DataModel.xcdatamodeld */; }; + 14AFFAF01C3C00E0001AD02C /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6051C3BC9E80066FAC8 /* CollectionCell.swift */; }; + 14AFFAF11C3C00E3001AD02C /* DataModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6061C3BC9E80066FAC8 /* DataModel.xcdatamodeld */; }; + 14AFFAF21C3C00E5001AD02C /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1498B6081C3BC9E80066FAC8 /* LoadingView.swift */; }; 14F3A67D1BE01B8500789E22 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14F3A67C1BE01B8500789E22 /* AppDelegate.swift */; }; 14F3A6821BE01B8500789E22 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 14F3A6811BE01B8500789E22 /* Assets.xcassets */; }; 14F3A6851BE01B8500789E22 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 14F3A6831BE01B8500789E22 /* LaunchScreen.storyboard */; }; @@ -41,10 +55,8 @@ 14F3A6C11BE01BA900789E22 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 14F3A6C01BE01BA900789E22 /* AppDelegate.m */; }; 14F3A6C61BE01BA900789E22 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 14F3A6C51BE01BA900789E22 /* Assets.xcassets */; }; 14F3A6C91BE01BA900789E22 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 14F3A6C71BE01BA900789E22 /* LaunchScreen.storyboard */; }; - 14F3A6DD1BE01D6E00789E22 /* CollectionCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 14F3A6D61BE01D6E00789E22 /* CollectionCell.m */; }; 14F3A6DE1BE01D6E00789E22 /* FooterExampleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 14F3A6D81BE01D6E00789E22 /* FooterExampleView.m */; }; 14F3A6E01BE01D6E00789E22 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 14F3A6DC1BE01D6E00789E22 /* ViewController.m */; }; - 14F3A6E31BE01D9200789E22 /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14F3A6E11BE01D9200789E22 /* CollectionCell.swift */; }; 14F3A6E41BE01D9200789E22 /* CollectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14F3A6E21BE01D9200789E22 /* CollectionController.swift */; }; 14F3A6E71BE01DD000789E22 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 14F3A6E61BE01DD000789E22 /* ViewController.m */; }; 14F3A6E91BE01DE800789E22 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14F3A6E81BE01DE800789E22 /* ViewController.swift */; }; @@ -52,7 +64,6 @@ 14F535971C3A7E9C00671EDF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 14F535961C3A7E9C00671EDF /* Assets.xcassets */; }; 14F5359A1C3A7E9C00671EDF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 14F535981C3A7E9C00671EDF /* LaunchScreen.storyboard */; }; 14F535A01C3A7EC000671EDF /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14F5359F1C3A7EC000671EDF /* ViewController.swift */; }; - 14F7B07A1C3AB1FB00AE779F /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14F7B0791C3AB1FB00AE779F /* CollectionCell.swift */; }; 14F7B07C1C3AB23000AE779F /* CollectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14F7B07B1C3AB23000AE779F /* CollectionController.swift */; }; 2D882E449EE09E09FD4820E5 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B49785EF9F4AAF152E01ABC3 /* Pods.framework */; }; 695779CF868D3C156A788297 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B49785EF9F4AAF152E01ABC3 /* Pods.framework */; }; @@ -64,18 +75,16 @@ /* Begin PBXFileReference section */ 141D2EE31BE021500028F879 /* CustomCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CustomCell.swift; sourceTree = ""; }; - 1458F8141C3AA548000652AF /* LoadingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = ""; }; 146205801C3AB0E400D78FC5 /* InfiniteCollectionSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = InfiniteCollectionSwift.app; sourceTree = BUILT_PRODUCTS_DIR; }; 146205821C3AB0E400D78FC5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 146205841C3AB0E400D78FC5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 146205871C3AB0E400D78FC5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 146205891C3AB0E400D78FC5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 1462058E1C3AB10500D78FC5 /* LoadingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = ""; }; 146D72AC1AB782920058798C /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 146D72B11AB782920058798C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 148C57711C0EBCB500546AEF /* DataModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = DataModel.xcdatamodel; sourceTree = ""; }; - 148C57781C0EBCE900546AEF /* CollectionObjC-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CollectionObjC-Bridging-Header.h"; sourceTree = ""; }; - 148C57791C0EBCE900546AEF /* TableObjC-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TableObjC-Bridging-Header.h"; sourceTree = ""; }; + 1498B6051C3BC9E80066FAC8 /* CollectionCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionCell.swift; sourceTree = ""; }; + 1498B6071C3BC9E80066FAC8 /* DataModel.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = DataModel.xcdatamodel; sourceTree = ""; }; + 1498B6081C3BC9E80066FAC8 /* LoadingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = ""; }; 149AF1901C0EB9EF00BA0907 /* DATASourceDelegateTableSwift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DATASourceDelegateTableSwift.app; sourceTree = BUILT_PRODUCTS_DIR; }; 149AF1921C0EB9EF00BA0907 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 149AF1971C0EB9EF00BA0907 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -112,13 +121,10 @@ 14F3A6C51BE01BA900789E22 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 14F3A6C81BE01BA900789E22 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 14F3A6CA1BE01BA900789E22 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 14F3A6D51BE01D6E00789E22 /* CollectionCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollectionCell.h; sourceTree = ""; }; - 14F3A6D61BE01D6E00789E22 /* CollectionCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CollectionCell.m; sourceTree = ""; }; 14F3A6D71BE01D6E00789E22 /* FooterExampleView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FooterExampleView.h; sourceTree = ""; }; 14F3A6D81BE01D6E00789E22 /* FooterExampleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FooterExampleView.m; sourceTree = ""; }; 14F3A6DB1BE01D6E00789E22 /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 14F3A6DC1BE01D6E00789E22 /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; - 14F3A6E11BE01D9200789E22 /* CollectionCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionCell.swift; sourceTree = ""; }; 14F3A6E21BE01D9200789E22 /* CollectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionController.swift; sourceTree = ""; }; 14F3A6E51BE01DD000789E22 /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 14F3A6E61BE01DD000789E22 /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; @@ -129,7 +135,6 @@ 14F535991C3A7E9C00671EDF /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 14F5359B1C3A7E9C00671EDF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 14F5359F1C3A7EC000671EDF /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 14F7B0791C3AB1FB00AE779F /* CollectionCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionCell.swift; sourceTree = ""; }; 14F7B07B1C3AB23000AE779F /* CollectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionController.swift; sourceTree = ""; }; 378599159DA682BF1388E3CC /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; B49785EF9F4AAF152E01ABC3 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -208,8 +213,6 @@ children = ( 146205821C3AB0E400D78FC5 /* AppDelegate.swift */, 14F7B07B1C3AB23000AE779F /* CollectionController.swift */, - 14F7B0791C3AB1FB00AE779F /* CollectionCell.swift */, - 1462058E1C3AB10500D78FC5 /* LoadingView.swift */, 146205841C3AB0E400D78FC5 /* Assets.xcassets */, 146205861C3AB0E400D78FC5 /* LaunchScreen.storyboard */, 146205891C3AB0E400D78FC5 /* Info.plist */, @@ -222,7 +225,7 @@ children = ( 14C136501AB7849300B7B07A /* Metadata */, 146D72AF1AB782920058798C /* Tests */, - 148C576F1C0EBC7A00546AEF /* Models */, + 1498B6041C3BC9E80066FAC8 /* Library */, 14F3A67B1BE01B8500789E22 /* CollectionSwift */, 14F3A68F1BE01B9200789E22 /* CollectionObjC */, 14F3A6A71BE01B9C00789E22 /* TableSwift */, @@ -270,14 +273,14 @@ name = "Supporting Files"; sourceTree = ""; }; - 148C576F1C0EBC7A00546AEF /* Models */ = { + 1498B6041C3BC9E80066FAC8 /* Library */ = { isa = PBXGroup; children = ( - 148C57701C0EBCB500546AEF /* DataModel.xcdatamodeld */, - 148C57781C0EBCE900546AEF /* CollectionObjC-Bridging-Header.h */, - 148C57791C0EBCE900546AEF /* TableObjC-Bridging-Header.h */, + 1498B6051C3BC9E80066FAC8 /* CollectionCell.swift */, + 1498B6061C3BC9E80066FAC8 /* DataModel.xcdatamodeld */, + 1498B6081C3BC9E80066FAC8 /* LoadingView.swift */, ); - path = Models; + path = Library; sourceTree = ""; }; 149AF1911C0EB9EF00BA0907 /* DATASourceDelegateTableSwift */ = { @@ -308,7 +311,6 @@ isa = PBXGroup; children = ( 14F3A67C1BE01B8500789E22 /* AppDelegate.swift */, - 14F3A6E11BE01D9200789E22 /* CollectionCell.swift */, 14F3A6E21BE01D9200789E22 /* CollectionController.swift */, 14F3A6811BE01B8500789E22 /* Assets.xcassets */, 14F3A6831BE01B8500789E22 /* LaunchScreen.storyboard */, @@ -322,8 +324,6 @@ children = ( 14F3A6931BE01B9200789E22 /* AppDelegate.h */, 14F3A6941BE01B9200789E22 /* AppDelegate.m */, - 14F3A6D51BE01D6E00789E22 /* CollectionCell.h */, - 14F3A6D61BE01D6E00789E22 /* CollectionCell.m */, 14F3A6D71BE01D6E00789E22 /* FooterExampleView.h */, 14F3A6D81BE01D6E00789E22 /* FooterExampleView.m */, 14F3A6DB1BE01D6E00789E22 /* ViewController.h */, @@ -385,7 +385,6 @@ children = ( 14F535941C3A7E9C00671EDF /* AppDelegate.swift */, 14F5359F1C3A7EC000671EDF /* ViewController.swift */, - 1458F8141C3AA548000652AF /* LoadingView.swift */, 14F535961C3A7E9C00671EDF /* Assets.xcassets */, 14F535981C3A7E9C00671EDF /* LaunchScreen.storyboard */, 14F5359B1C3A7E9C00671EDF /* Info.plist */, @@ -1029,10 +1028,10 @@ buildActionMask = 2147483647; files = ( 146205831C3AB0E400D78FC5 /* AppDelegate.swift in Sources */, + 1498B6161C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */, 14F7B07C1C3AB23000AE779F /* CollectionController.swift in Sources */, - 1462058D1C3AB0E900D78FC5 /* DataModel.xcdatamodeld in Sources */, - 146205901C3AB10500D78FC5 /* LoadingView.swift in Sources */, - 14F7B07A1C3AB1FB00AE779F /* CollectionCell.swift in Sources */, + 1498B61D1C3BC9E80066FAC8 /* LoadingView.swift in Sources */, + 1498B60F1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1040,8 +1039,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 14AFFAF11C3C00E3001AD02C /* DataModel.xcdatamodeld in Sources */, + 14AFFAF21C3C00E5001AD02C /* LoadingView.swift in Sources */, 14A139B41AEFC72B00AD732F /* Tests.swift in Sources */, - 148C57721C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */, + 14AFFAF01C3C00E0001AD02C /* CollectionCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1050,8 +1051,10 @@ buildActionMask = 2147483647; files = ( 149AF1A11C0EBA0700BA0907 /* ViewController.swift in Sources */, - 148C57771C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */, + 1498B6141C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */, 149AF1931C0EB9EF00BA0907 /* AppDelegate.swift in Sources */, + 1498B61B1C3BC9E80066FAC8 /* LoadingView.swift in Sources */, + 1498B60D1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1060,9 +1063,10 @@ buildActionMask = 2147483647; files = ( 14F3A67D1BE01B8500789E22 /* AppDelegate.swift in Sources */, - 148C57731C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */, + 1498B6101C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */, 14F3A6E41BE01D9200789E22 /* CollectionController.swift in Sources */, - 14F3A6E31BE01D9200789E22 /* CollectionCell.swift in Sources */, + 1498B6171C3BC9E80066FAC8 /* LoadingView.swift in Sources */, + 1498B6091C3BC9E80066FAC8 /* CollectionCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1071,11 +1075,12 @@ buildActionMask = 2147483647; files = ( 14F3A6E01BE01D6E00789E22 /* ViewController.m in Sources */, - 148C57741C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */, 14F3A6951BE01B9200789E22 /* AppDelegate.m in Sources */, 14F3A6921BE01B9200789E22 /* main.m in Sources */, - 14F3A6DD1BE01D6E00789E22 /* CollectionCell.m in Sources */, + 1498B6111C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */, 14F3A6DE1BE01D6E00789E22 /* FooterExampleView.m in Sources */, + 1498B6181C3BC9E80066FAC8 /* LoadingView.swift in Sources */, + 1498B60A1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1084,9 +1089,11 @@ buildActionMask = 2147483647; files = ( 14F3A6E91BE01DE800789E22 /* ViewController.swift in Sources */, - 148C57751C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */, + 1498B6121C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */, 141D2EE41BE021500028F879 /* CustomCell.swift in Sources */, 14F3A6A91BE01B9C00789E22 /* AppDelegate.swift in Sources */, + 1498B60B1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */, + 1498B6191C3BC9E80066FAC8 /* LoadingView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1095,9 +1102,11 @@ buildActionMask = 2147483647; files = ( 14F3A6C11BE01BA900789E22 /* AppDelegate.m in Sources */, - 148C57761C0EBCB500546AEF /* DataModel.xcdatamodeld in Sources */, + 1498B6131C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */, 14F3A6E71BE01DD000789E22 /* ViewController.m in Sources */, 14F3A6BE1BE01BA900789E22 /* main.m in Sources */, + 1498B60C1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */, + 1498B61A1C3BC9E80066FAC8 /* LoadingView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1105,10 +1114,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 14AEBDA51C3A8F4F00A26353 /* DataModel.xcdatamodeld in Sources */, - 1458F8151C3AA548000652AF /* LoadingView.swift in Sources */, 14F535A01C3A7EC000671EDF /* ViewController.swift in Sources */, + 1498B6151C3BC9E80066FAC8 /* DataModel.xcdatamodeld in Sources */, 14F535951C3A7E9C00671EDF /* AppDelegate.swift in Sources */, + 1498B61C1C3BC9E80066FAC8 /* LoadingView.swift in Sources */, + 1498B60E1C3BC9E80066FAC8 /* CollectionCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1386,7 +1396,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = demo.CollectionObjC; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "Models/CollectionObjC-Bridging-Header.h"; + SWIFT_INSTALL_OBJC_HEADER = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; @@ -1404,7 +1414,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = demo.CollectionObjC; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "Models/CollectionObjC-Bridging-Header.h"; + SWIFT_INSTALL_OBJC_HEADER = YES; }; name = Release; }; @@ -1452,7 +1462,6 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = demo.TableObjC; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "Models/TableObjC-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; @@ -1470,7 +1479,6 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = demo.TableObjC; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_OBJC_BRIDGING_HEADER = "Models/TableObjC-Bridging-Header.h"; }; name = Release; }; @@ -1592,12 +1600,12 @@ /* End XCConfigurationList section */ /* Begin XCVersionGroup section */ - 148C57701C0EBCB500546AEF /* DataModel.xcdatamodeld */ = { + 1498B6061C3BC9E80066FAC8 /* DataModel.xcdatamodeld */ = { isa = XCVersionGroup; children = ( - 148C57711C0EBCB500546AEF /* DataModel.xcdatamodel */, + 1498B6071C3BC9E80066FAC8 /* DataModel.xcdatamodel */, ); - currentVersion = 148C57711C0EBCB500546AEF /* DataModel.xcdatamodel */; + currentVersion = 1498B6071C3BC9E80066FAC8 /* DataModel.xcdatamodel */; path = DataModel.xcdatamodeld; sourceTree = ""; versionGroupType = wrapper.xcdatamodel; diff --git a/Demo.xcodeproj/xcshareddata/xcschemes/CollectionObjC.xcscheme b/Demo.xcodeproj/xcshareddata/xcschemes/CollectionObjC.xcscheme index 9f265cf..15dc57e 100644 --- a/Demo.xcodeproj/xcshareddata/xcschemes/CollectionObjC.xcscheme +++ b/Demo.xcodeproj/xcshareddata/xcschemes/CollectionObjC.xcscheme @@ -1,6 +1,6 @@ Bool { if let window = self.window { + let bounds = UIScreen.mainScreen().bounds + let layout = UICollectionViewFlowLayout() layout.itemSize = CGSize(width: 120, height: 120) layout.sectionInset = UIEdgeInsets(top: 15, left: 0, bottom: 15, right: 0) + layout.headerReferenceSize = CGSize(width: bounds.size.width, height: 60) let viewController = CollectionController(layout: layout, dataStack: self.dataStack) window.rootViewController = UINavigationController(rootViewController: viewController) diff --git a/InfiniteCollectionSwift/CollectionCell.swift b/InfiniteCollectionSwift/CollectionCell.swift deleted file mode 100644 index 23c4b34..0000000 --- a/InfiniteCollectionSwift/CollectionCell.swift +++ /dev/null @@ -1,25 +0,0 @@ -import UIKit - -class CollectionCell: UICollectionViewCell { - static let Identifier = "CollectionCellIdentifier" - - lazy var textLabel: UILabel = { - let label = UILabel(frame: CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height)) - label.textAlignment = .Center - - return label - }() - - override init(frame: CGRect) { - super.init(frame: frame) - - self.contentView.layer.borderWidth = 1 - self.contentView.layer.borderColor = UIColor.lightGrayColor().CGColor - - addSubview(textLabel) - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } -} diff --git a/InfiniteCollectionSwift/CollectionController.swift b/InfiniteCollectionSwift/CollectionController.swift index 395cd93..d720f35 100644 --- a/InfiniteCollectionSwift/CollectionController.swift +++ b/InfiniteCollectionSwift/CollectionController.swift @@ -5,17 +5,18 @@ import DATASource import CoreData class CollectionController: UICollectionViewController { - var dataStack: DATAStack? + unowned var dataStack: DATAStack lazy var dataSource: DATASource = { - guard let collectionView = self.collectionView, mainContext = self.dataStack?.mainContext else { fatalError("CollectionView is nil") } + guard let collectionView = self.collectionView else { fatalError("CollectionView is nil") } let request: NSFetchRequest = NSFetchRequest(entityName: "User") request.sortDescriptors = [ - NSSortDescriptor(key: "name", ascending: true) + NSSortDescriptor(key: "name", ascending: true), + NSSortDescriptor(key: "firstLetterOfName", ascending: true) ] - let dataSource = DATASource(collectionView: collectionView, cellIdentifier: CollectionCell.Identifier, fetchRequest: request, mainContext: mainContext, configuration: { cell, item, indexPath in + let dataSource = DATASource(collectionView: collectionView, cellIdentifier: CollectionCell.Identifier, fetchRequest: request, mainContext: self.dataStack.mainContext, sectionName: "firstLetterOfName", configuration: { cell, item, indexPath in let collectionCell = cell as! CollectionCell collectionCell.textLabel.text = item.valueForKey("name") as? String }) @@ -30,9 +31,9 @@ class CollectionController: UICollectionViewController { }() init(layout: UICollectionViewLayout, dataStack: DATAStack) { - super.init(collectionViewLayout: layout) - self.dataStack = dataStack + + super.init(collectionViewLayout: layout) } required init?(coder aDecoder: NSCoder) { @@ -78,11 +79,14 @@ class CollectionController: UICollectionViewController { func loadItems(initialIndex: Int, completion: (Void -> Void)?) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { - self.dataStack!.performInNewBackgroundContext { backgroundContext in + self.dataStack.performInNewBackgroundContext { backgroundContext in if let entity = NSEntityDescription.entityForName("User", inManagedObjectContext: backgroundContext) { - for i in initialIndex.. 0 { - if let sections = self.sectionChanges[.Delete] { - let filtered = deletes.filter({ element -> Bool in - return (sections.containsIndex(element.section)) - }) - self.objectChanges[.Delete] = filtered - } - } - } - - if let inserts = self.objectChanges[.Insert] { - if inserts.count > 0 { - if let sections = self.sectionChanges[.Insert] { - let filtered = inserts.filter({ element -> Bool in - return (sections.containsIndex(element.section)) - }) - - self.objectChanges[.Insert] = filtered - } - } - } - if let collectionView = self.collectionView { collectionView.performBatchUpdates({ if let deletedSections = self.sectionChanges[.Delete] { diff --git a/TableSwift/ViewController.swift b/TableSwift/ViewController.swift index ecf9891..09e8f8e 100644 --- a/TableSwift/ViewController.swift +++ b/TableSwift/ViewController.swift @@ -4,7 +4,7 @@ import DATASource import CoreData class ViewController: UITableViewController { - var dataStack: DATAStack? + weak var dataStack: DATAStack? lazy var dataSource: DATASource = { let request: NSFetchRequest = NSFetchRequest(entityName: "User")