Skip to content

Commit

Permalink
Update for Swift 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MoZhouqi committed Apr 17, 2015
1 parent 84a630c commit 8d33663
Show file tree
Hide file tree
Showing 89 changed files with 5,131 additions and 692 deletions.
185 changes: 72 additions & 113 deletions PhotoBrowser.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions PhotoBrowser.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

451 changes: 0 additions & 451 deletions PhotoBrowser/Alamofire-master/Alamofire.xcodeproj/project.pbxproj

This file was deleted.

This file was deleted.

28 changes: 16 additions & 12 deletions PhotoBrowser/AppDelegate.swift
Expand Up @@ -9,6 +9,7 @@
import UIKit
import CoreData
import Alamofire
import FastImageCache

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, FICImageCacheDelegate {
Expand All @@ -20,8 +21,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, FICImageCacheDelegate {
// Override point for customization after application launch.

FastImageCacheHelper.setUp(self)
let navController = window!.rootViewController as UINavigationController
let photoBrowserCollectionViewController = navController.topViewController as PhotoBrowserCollectionViewController
let navController = window!.rootViewController as! UINavigationController
let photoBrowserCollectionViewController = navController.topViewController as! PhotoBrowserCollectionViewController
photoBrowserCollectionViewController.coreDataStack = coreDataStack

return true
Expand Down Expand Up @@ -54,20 +55,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate, FICImageCacheDelegate {

//MARK: FICImageCacheDelegate

func imageCache(imageCache: FICImageCache!, wantsSourceImageForEntity entity: PhotoInfo!, withFormatName formatName: String!, completionBlock: FICImageRequestCompletionBlock!) {
let imageURL = entity.sourceImageURLWithFormatName(formatName)
let request = NSURLRequest(URL: imageURL)

entity.request = Alamofire.request(.GET, request).validate(contentType: ["image/*"]).responseImage() {
(_, _, image, error) in
if (error == nil) {
completionBlock(image)
func imageCache(imageCache: FICImageCache!, wantsSourceImageForEntity entity: FICEntity!, withFormatName formatName: String!, completionBlock: FICImageRequestCompletionBlock!) {
if let entity = entity as? PhotoInfo {
let imageURL = entity.sourceImageURLWithFormatName(formatName)
let request = NSURLRequest(URL: imageURL)

entity.request = Alamofire.request(.GET, request).validate(contentType: ["image/*"]).responseImage() {
(_, _, image, error) in
if (error == nil) {
completionBlock(image)
}
}
}
}

func imageCache(imageCache: FICImageCache!, cancelImageLoadingForEntity entity: PhotoInfo!, withFormatName formatName: String!) {
if let request = entity.request {
func imageCache(imageCache: FICImageCache!, cancelImageLoadingForEntity entity: FICEntity!, withFormatName formatName: String!) {

if let entity = entity as? PhotoInfo, request = entity.request {
request.cancel()
entity.request = nil
//println("be canceled:\(entity.UUID)")
Expand Down
2 changes: 1 addition & 1 deletion PhotoBrowser/CoreDataStack.swift
Expand Up @@ -61,7 +61,7 @@ class CoreDataStack {
func applicationDocumentsDirectory() -> NSURL {

let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
return urls[urls.count-1] as NSURL
return urls[urls.count-1] as! NSURL
}

}
1 change: 1 addition & 0 deletions PhotoBrowser/FastImageCacheHelper.swift
Expand Up @@ -8,6 +8,7 @@

import Foundation
import UIKit
import FastImageCache

let KMPhotoImageFormatFamily = "KMPhotoImageFormatFamily"
let KMSmallImageFormatName = "KMSmallImageFormatName"
Expand Down
21 changes: 10 additions & 11 deletions PhotoBrowser/OauthLoginViewController.swift
Expand Up @@ -7,9 +7,11 @@
//

import UIKit
import Alamofire
import Foundation
import CoreData
import Alamofire
import SwiftyJSON

class OauthLoginViewController: UIViewController {

@IBOutlet weak var webView: UIWebView!
Expand Down Expand Up @@ -38,7 +40,7 @@ class OauthLoginViewController: UIViewController {

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "unwindToPhotoBrowser" && segue.destinationViewController.isKindOfClass(PhotoBrowserCollectionViewController.classForCoder()) {
let photoBrowserCollectionViewController = segue.destinationViewController as PhotoBrowserCollectionViewController
let photoBrowserCollectionViewController = segue.destinationViewController as! PhotoBrowserCollectionViewController
if let user = sender?.valueForKey("user") as? User {
photoBrowserCollectionViewController.user = user

Expand Down Expand Up @@ -74,15 +76,12 @@ extension OauthLoginViewController: UIWebViewDelegate {
//println(jsonObject)
let json = JSON(jsonObject!)

if let accessToken = json["access_token"].string{
if let userID = json["user"]["id"].string {
let user =
NSEntityDescription.insertNewObjectForEntityForName("User", inManagedObjectContext: self.coreDataStack.context) as User
user.userID = userID
user.accessToken = accessToken
self.coreDataStack.saveContext()
self.performSegueWithIdentifier("unwindToPhotoBrowser", sender: ["user": user])
}
if let accessToken = json["access_token"].string, userID = json["user"]["id"].string {
let user = NSEntityDescription.insertNewObjectForEntityForName("User", inManagedObjectContext: self.coreDataStack.context) as! User
user.userID = userID
user.accessToken = accessToken
self.coreDataStack.saveContext()
self.performSegueWithIdentifier("unwindToPhotoBrowser", sender: ["user": user])
}
}

Expand Down
18 changes: 10 additions & 8 deletions PhotoBrowser/PhotoBrowserCollectionViewController.swift
Expand Up @@ -8,8 +8,10 @@

import UIKit
import Foundation
import Alamofire
import CoreData
import Alamofire
import FastImageCache
import SwiftyJSON

class PhotoBrowserCollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {

Expand Down Expand Up @@ -48,7 +50,7 @@ class PhotoBrowserCollectionViewController: UICollectionViewController, UICollec
var error: NSError?
if let fetchRequest = coreDataStack.model.fetchRequestTemplateForName("UserFetchRequest") {

let results = coreDataStack.context.executeFetchRequest(fetchRequest,error: &error) as [User]
let results = coreDataStack.context.executeFetchRequest(fetchRequest,error: &error) as! [User]
user = results.first
}

Expand Down Expand Up @@ -78,7 +80,7 @@ class PhotoBrowserCollectionViewController: UICollectionViewController, UICollec
}

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(PhotoBrowserCellIdentifier, forIndexPath: indexPath) as PhotoBrowserCollectionViewCell
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(PhotoBrowserCellIdentifier, forIndexPath: indexPath) as! PhotoBrowserCollectionViewCell
let sharedImageCache = FICImageCache.sharedImageCache()
cell.imageView.image = nil

Expand All @@ -92,7 +94,7 @@ class PhotoBrowserCollectionViewController: UICollectionViewController, UICollec

sharedImageCache.retrieveImageForEntity(photo, withFormatName: formatName, completionBlock: {
(photoInfo, _, image) -> Void in
if (photoInfo as PhotoInfo) == cell.photoInfo {
if (photoInfo as! PhotoInfo) == cell.photoInfo {
cell.imageView.image = image
}
})
Expand All @@ -101,7 +103,7 @@ class PhotoBrowserCollectionViewController: UICollectionViewController, UICollec
}

override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
let footerView = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: PhotoBrowserFooterViewIdentifier, forIndexPath: indexPath) as PhotoBrowserLoadingCollectionView
let footerView = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: PhotoBrowserFooterViewIdentifier, forIndexPath: indexPath) as! PhotoBrowserLoadingCollectionView
if nextURLRequest == nil {
footerView.spinner.stopAnimating()
} else {
Expand Down Expand Up @@ -155,7 +157,7 @@ class PhotoBrowserCollectionViewController: UICollectionViewController, UICollec
(_ , _, jsonObject, error) in

if (error == nil) {
// println(jsonObject)
//println(jsonObject)
let json = JSON(jsonObject!)

if (json["meta"]["code"].intValue == 200) {
Expand Down Expand Up @@ -215,10 +217,10 @@ class PhotoBrowserCollectionViewController: UICollectionViewController, UICollec
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "show photo" && segue.destinationViewController.isKindOfClass(PhotoViewerViewController.classForCoder()) {
let photoViewerViewController = segue.destinationViewController as PhotoViewerViewController
let photoViewerViewController = segue.destinationViewController as! PhotoViewerViewController
photoViewerViewController.photoInfo = sender?.valueForKey("photoInfo") as? PhotoInfo
} else if segue.identifier == "login" && segue.destinationViewController.isKindOfClass(UINavigationController.classForCoder()) {
let navigationController = segue.destinationViewController as UINavigationController
let navigationController = segue.destinationViewController as! UINavigationController
if let oauthLoginViewController = navigationController.topViewController as? OauthLoginViewController {
oauthLoginViewController.coreDataStack = coreDataStack
}
Expand Down
3 changes: 2 additions & 1 deletion PhotoBrowser/PhotoInfo.swift
Expand Up @@ -8,6 +8,7 @@

import Foundation
import Alamofire
import FastImageCache

class PhotoInfo: NSObject, FICEntity {
var UUID: String {
Expand All @@ -29,7 +30,7 @@ class PhotoInfo: NSObject, FICEntity {
}

override func isEqual(object: AnyObject?) -> Bool {
return (object as PhotoInfo).UUID == self.UUID
return (object as! PhotoInfo).UUID == self.UUID
}

func sourceImageURLWithFormatName(formatName: String!) -> NSURL! {
Expand Down
5 changes: 3 additions & 2 deletions PhotoBrowser/PhotoViewerViewController.swift
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import FastImageCache

class PhotoViewerViewController: UIViewController, UIScrollViewDelegate {

Expand Down Expand Up @@ -72,7 +73,7 @@ class PhotoViewerViewController: UIViewController, UIScrollViewDelegate {

// MARK: ScrollView

func scrollViewDidZoom(scrollView: UIScrollView!) {
func scrollViewDidZoom(scrollView: UIScrollView) {
self.centerScrollViewContents()
}

Expand All @@ -95,7 +96,7 @@ class PhotoViewerViewController: UIViewController, UIScrollViewDelegate {
self.imageView.frame = contentsFrame
}

func viewForZoomingInScrollView(scrollView: UIScrollView!) -> UIView! {
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
return self.imageView
}

Expand Down
7 changes: 7 additions & 0 deletions Podfile
@@ -0,0 +1,7 @@
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Alamofire', '~> 1.2'
pod 'SwiftyJSON', '~> 2.2.0'
pod 'FastImageCache', '~> 1.3', :inhibit_warnings => true
16 changes: 16 additions & 0 deletions Podfile.lock
@@ -0,0 +1,16 @@
PODS:
- Alamofire (1.2.0)
- FastImageCache (1.3)
- SwiftyJSON (2.2.0)

DEPENDENCIES:
- Alamofire (~> 1.2)
- FastImageCache (~> 1.3)
- SwiftyJSON (~> 2.2.0)

SPEC CHECKSUMS:
Alamofire: d765c5c1713aa64106b0228aaa600a1e6851f68d
FastImageCache: 25f214fd46405daca3d1995d783fb83b9036c62e
SwiftyJSON: 0b3e6c07af17ff745e77e8e9984097b55c956e5c

COCOAPODS: 0.36.4
19 changes: 19 additions & 0 deletions Pods/Alamofire/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8d33663

Please sign in to comment.