Skip to content

Commit

Permalink
Updated photos framework post.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Grant committed Jul 2, 2015
1 parent 2329184 commit f080d3f
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 206 deletions.
130 changes: 1 addition & 129 deletions 20-photos-framework/StarGallery/StarGallery.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,18 @@
226F368C19A5329A00317C2F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 226F368B19A5329A00317C2F /* AppDelegate.swift */; };
226F369119A5329A00317C2F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 226F368F19A5329A00317C2F /* Main.storyboard */; };
226F369319A5329A00317C2F /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 226F369219A5329A00317C2F /* Images.xcassets */; };
226F369F19A5329A00317C2F /* StarGalleryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 226F369E19A5329A00317C2F /* StarGalleryTests.swift */; };
226F36A919A53B1500317C2F /* PhotosCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 226F36A819A53B1500317C2F /* PhotosCollectionViewController.swift */; };
226F36AB19A542EC00317C2F /* PhotosCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 226F36AA19A542EC00317C2F /* PhotosCollectionViewCell.swift */; };
22732A7419A60283006036BD /* ImageCacheController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22732A7319A60283006036BD /* ImageCacheController.swift */; };
22EDB8491AD6888E008515E4 /* Launch Screen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22EDB8471AD6888E008515E4 /* Launch Screen.xib */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
226F369919A5329A00317C2F /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 226F367E19A5329A00317C2F /* Project object */;
proxyType = 1;
remoteGlobalIDString = 226F368519A5329A00317C2F;
remoteInfo = StarGallery;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
226F368619A5329A00317C2F /* StarGallery.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = StarGallery.app; sourceTree = BUILT_PRODUCTS_DIR; };
226F368A19A5329A00317C2F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
226F368B19A5329A00317C2F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
226F369019A5329A00317C2F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
226F369219A5329A00317C2F /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
226F369819A5329A00317C2F /* StarGalleryTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StarGalleryTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
226F369D19A5329A00317C2F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
226F369E19A5329A00317C2F /* StarGalleryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StarGalleryTests.swift; sourceTree = "<group>"; };
226F36A819A53B1500317C2F /* PhotosCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosCollectionViewController.swift; sourceTree = "<group>"; };
226F36AA19A542EC00317C2F /* PhotosCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PhotosCollectionViewCell.swift; sourceTree = "<group>"; };
22732A7319A60283006036BD /* ImageCacheController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCacheController.swift; sourceTree = "<group>"; };
Expand All @@ -50,21 +36,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
226F369519A5329A00317C2F /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
226F367D19A5329A00317C2F = {
isa = PBXGroup;
children = (
226F368819A5329A00317C2F /* StarGallery */,
226F369B19A5329A00317C2F /* StarGalleryTests */,
226F368719A5329A00317C2F /* Products */,
);
sourceTree = "<group>";
Expand All @@ -73,7 +51,6 @@
isa = PBXGroup;
children = (
226F368619A5329A00317C2F /* StarGallery.app */,
226F369819A5329A00317C2F /* StarGalleryTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -101,23 +78,6 @@
name = "Supporting Files";
sourceTree = "<group>";
};
226F369B19A5329A00317C2F /* StarGalleryTests */ = {
isa = PBXGroup;
children = (
226F369E19A5329A00317C2F /* StarGalleryTests.swift */,
226F369C19A5329A00317C2F /* Supporting Files */,
);
path = StarGalleryTests;
sourceTree = "<group>";
};
226F369C19A5329A00317C2F /* Supporting Files */ = {
isa = PBXGroup;
children = (
226F369D19A5329A00317C2F /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -138,40 +98,19 @@
productReference = 226F368619A5329A00317C2F /* StarGallery.app */;
productType = "com.apple.product-type.application";
};
226F369719A5329A00317C2F /* StarGalleryTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = 226F36A519A5329A00317C2F /* Build configuration list for PBXNativeTarget "StarGalleryTests" */;
buildPhases = (
226F369419A5329A00317C2F /* Sources */,
226F369519A5329A00317C2F /* Frameworks */,
226F369619A5329A00317C2F /* Resources */,
);
buildRules = (
);
dependencies = (
226F369A19A5329A00317C2F /* PBXTargetDependency */,
);
name = StarGalleryTests;
productName = StarGalleryTests;
productReference = 226F369819A5329A00317C2F /* StarGalleryTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
226F367E19A5329A00317C2F /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0600;
ORGANIZATIONNAME = ShinobiControls;
TargetAttributes = {
226F368519A5329A00317C2F = {
CreatedOnToolsVersion = 6.0;
};
226F369719A5329A00317C2F = {
CreatedOnToolsVersion = 6.0;
TestTargetID = 226F368519A5329A00317C2F;
};
};
};
buildConfigurationList = 226F368119A5329A00317C2F /* Build configuration list for PBXProject "StarGallery" */;
Expand All @@ -188,7 +127,6 @@
projectRoot = "";
targets = (
226F368519A5329A00317C2F /* StarGallery */,
226F369719A5329A00317C2F /* StarGalleryTests */,
);
};
/* End PBXProject section */
Expand All @@ -204,13 +142,6 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
226F369619A5329A00317C2F /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand All @@ -225,24 +156,8 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
226F369419A5329A00317C2F /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
226F369F19A5329A00317C2F /* StarGalleryTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
226F369A19A5329A00317C2F /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 226F368519A5329A00317C2F /* StarGallery */;
targetProxy = 226F369919A5329A00317C2F /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
226F368F19A5329A00317C2F /* Main.storyboard */ = {
isa = PBXVariantGroup;
Expand Down Expand Up @@ -362,40 +277,6 @@
};
name = Release;
};
226F36A619A5329A00317C2F /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = StarGalleryTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/StarGallery.app/StarGallery";
};
name = Debug;
};
226F36A719A5329A00317C2F /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
INFOPLIST_FILE = StarGalleryTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/StarGallery.app/StarGallery";
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
Expand All @@ -417,15 +298,6 @@
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
226F36A519A5329A00317C2F /* Build configuration list for PBXNativeTarget "StarGalleryTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
226F36A619A5329A00317C2F /* Debug */,
226F36A719A5329A00317C2F /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 226F367E19A5329A00317C2F /* Project object */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="9Sn-fn-awD">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.20" systemVersion="14D131" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="9Sn-fn-awD">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
</dependencies>
<scenes>
<!--Photos Collection View Controller-->
Expand All @@ -20,7 +21,7 @@
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="Cell" id="vSe-P5-cFX" customClass="PhotosCollectionViewCell" customModule="StarGallery" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<rect key="frame" x="140" y="0.0" width="320" height="320"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="320" height="320"/>
Expand All @@ -29,7 +30,7 @@
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="fNt-Fi-YeW">
<rect key="frame" x="0.0" y="0.0" width="320" height="320"/>
</imageView>
<button opaque="NO" alpha="0.40000000000000002" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="m9L-y3-uaH">
<button opaque="NO" alpha="0.40000000000000002" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="m9L-y3-uaH">
<rect key="frame" x="-20" y="212" width="128" height="128"/>
<color key="tintColor" red="1" green="0.86195106580000003" blue="0.15694230179999999" alpha="1" colorSpace="calibratedRGB"/>
<state key="normal" image="star">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,19 @@ class ImageCacheController {
self.cachedIndices.enumerateIndexesUsingBlock {
index, _ in
if !updatedCache.containsIndex(index) {
let asset: AnyObject! = self.images[index]
let asset: PHAsset! = self.images[index] as! PHAsset
self.imageCache.stopCachingImagesForAssets([asset], targetSize: self.targetSize, contentMode: self.contentMode, options: nil)
println("Stopping caching image \(index)")

print("Stopping caching image \(index)")
}
}

// And which are new?
updatedCache.enumerateIndexesUsingBlock {
index, _ in
if !self.cachedIndices.containsIndex(index) {
let asset: AnyObject! = self.images[index]
let asset: PHAsset! = self.images[index] as! PHAsset
self.imageCache.startCachingImagesForAssets([asset], targetSize: self.targetSize, contentMode: self.contentMode, options: nil)
println("Starting caching image \(index)")
print("Starting caching image \(index)")
}
}
cachedIndices = NSIndexSet(indexSet: updatedCache)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PhotosCollectionViewCell: UICollectionViewCell {

@IBAction func handleStarButtonPressed(sender: AnyObject) {
PHPhotoLibrary.sharedPhotoLibrary().performChanges({
let changeRequest = PHAssetChangeRequest(forAsset: self.imageAsset)
let changeRequest = PHAssetChangeRequest(forAsset: self.imageAsset!)
changeRequest.favorite = !self.imageAsset!.favorite
}, completionHandler: nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let reuseIdentifier = "Cell"

class PhotosCollectionViewController: UICollectionViewController, PHPhotoLibraryChangeObserver {

var images: PHFetchResult! = nil
var images: PHFetchResult!
let imageManager = PHCachingImageManager()
var imageCacheController: ImageCacheController!

Expand Down Expand Up @@ -55,21 +55,21 @@ class PhotosCollectionViewController: UICollectionViewController, PHPhotoLibrary
// MARK: - ScrollViewDelegate
override func scrollViewDidScroll(scrollView: UIScrollView) {
let indexPaths = collectionView?.indexPathsForVisibleItems()
imageCacheController.updateVisibleCells(indexPaths as! [NSIndexPath])
imageCacheController.updateVisibleCells(indexPaths as [NSIndexPath]!)
}

// MARK: - PHPhotoLibraryChangeObserver
func photoLibraryDidChange(changeInstance: PHChange!) {
func photoLibraryDidChange(changeInstance: PHChange) {
let changeDetails = changeInstance.changeDetailsForFetchResult(images)

self.images = changeDetails.fetchResultAfterChanges
self.images = changeDetails!.fetchResultAfterChanges
dispatch_async(dispatch_get_main_queue()) {
// Loop through the visible cell indices
let indexPaths = self.collectionView?.indexPathsForVisibleItems()
for indexPath in indexPaths as! [NSIndexPath] {
if changeDetails.changedIndexes.containsIndex(indexPath.item) {
for indexPath in indexPaths as [NSIndexPath]! {
if changeDetails!.changedIndexes!.containsIndex(indexPath.item) {
let cell = self.collectionView?.cellForItemAtIndexPath(indexPath) as! PhotosCollectionViewCell
cell.imageAsset = changeDetails.fetchResultAfterChanges[indexPath.item] as? PHAsset
cell.imageAsset = changeDetails!.fetchResultAfterChanges[indexPath.item] as? PHAsset
}
}
}
Expand Down
24 changes: 0 additions & 24 deletions 20-photos-framework/StarGallery/StarGalleryTests/Info.plist

This file was deleted.

This file was deleted.

0 comments on commit f080d3f

Please sign in to comment.