From d5b59756efdeb89d6d802e2813fca78454f5cf45 Mon Sep 17 00:00:00 2001 From: Antoine Barrault Date: Fri, 22 Apr 2016 09:04:51 -0300 Subject: [PATCH 1/2] add test to reproduce issue --- SKPhotoBrowserTests/SKPhotoBrowserTests.swift | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/SKPhotoBrowserTests/SKPhotoBrowserTests.swift b/SKPhotoBrowserTests/SKPhotoBrowserTests.swift index 7ee10a9..a6341b2 100644 --- a/SKPhotoBrowserTests/SKPhotoBrowserTests.swift +++ b/SKPhotoBrowserTests/SKPhotoBrowserTests.swift @@ -7,6 +7,14 @@ // import XCTest +@testable import SKPhotoBrowser + + +class FakeSKPhotoBrowser : SKPhotoBrowser { + override func setup () { + + } +} class SKPhotoBrowserTests: XCTestCase { @@ -19,12 +27,30 @@ class SKPhotoBrowserTests: XCTestCase { // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() } + - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. + func testSKPhotoArray() { + var images = [SKPhoto]() + let photo = SKPhoto.photoWithImage(UIImage())// add some UIImage + images.append(photo) + let _ = FakeSKPhotoBrowser(photos: images) } + func testSKLocalPhotoArray() { + var images = [SKLocalPhoto]() + let photo = SKLocalPhoto.photoWithImageURL("") + images.append(photo) + let _ = FakeSKPhotoBrowser(photos: images) + } + + func testSKPhotoProtocolArray() { + var images = [SKPhotoProtocol]() + let photo = SKPhoto.photoWithImage(UIImage())// add some UIImage + images.append(photo) + let _ = FakeSKPhotoBrowser(photos: images) + } + + func testPerformanceExample() { // This is an example of a performance test case. self.measureBlock { From 5d635c77d7962e5a215a2f10bf6d9e809660359c Mon Sep 17 00:00:00 2001 From: Antoine Barrault Date: Fri, 22 Apr 2016 09:41:10 -0300 Subject: [PATCH 2/2] fix issue #89 --- SKPhotoBrowser/SKPhotoBrowser.swift | 10 ++++++---- SKPhotoBrowserTests/SKPhotoBrowserTests.swift | 8 -------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index 6c8c3d7..21e5755 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -203,19 +203,21 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { setup() } - public convenience init(photos: [SKPhotoProtocol]) { + public convenience init(photos: [AnyObject]) { self.init(nibName: nil, bundle: nil) - for photo in photos { + let picutres = photos.flatMap {$0 as? SKPhotoProtocol} + for photo in picutres { photo.checkCache() self.photos.append(photo) } } - public convenience init(originImage: UIImage, photos: [SKPhotoProtocol], animatedFromView: UIView) { + public convenience init(originImage: UIImage, photos: [AnyObject], animatedFromView: UIView) { self.init(nibName: nil, bundle: nil) self.senderOriginImage = originImage self.senderViewForAnimation = animatedFromView - for photo in photos { + let picutres = photos.flatMap {$0 as? SKPhotoProtocol} + for photo in picutres { photo.checkCache() self.photos.append(photo) } diff --git a/SKPhotoBrowserTests/SKPhotoBrowserTests.swift b/SKPhotoBrowserTests/SKPhotoBrowserTests.swift index a6341b2..721497b 100644 --- a/SKPhotoBrowserTests/SKPhotoBrowserTests.swift +++ b/SKPhotoBrowserTests/SKPhotoBrowserTests.swift @@ -42,14 +42,6 @@ class SKPhotoBrowserTests: XCTestCase { images.append(photo) let _ = FakeSKPhotoBrowser(photos: images) } - - func testSKPhotoProtocolArray() { - var images = [SKPhotoProtocol]() - let photo = SKPhoto.photoWithImage(UIImage())// add some UIImage - images.append(photo) - let _ = FakeSKPhotoBrowser(photos: images) - } - func testPerformanceExample() { // This is an example of a performance test case.