Skip to content

Commit

Permalink
Merge branch 'swift2'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Lily/FileManager.swift
#	README.md
  • Loading branch information
kukushi committed Sep 11, 2015
2 parents 889c9cf + bf57be9 commit 75eb411
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 60 deletions.
9 changes: 8 additions & 1 deletion Lily.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@
52D138791AC59D9900B83A6C /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0630;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = kukushi;
TargetAttributes = {
52D138811AC59D9900B83A6C = {
Expand Down Expand Up @@ -287,6 +288,7 @@
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -345,6 +347,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -363,6 +366,7 @@
INFOPLIST_FILE = Lily/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kukushi.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -380,6 +384,7 @@
INFOPLIST_FILE = Lily/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kukushi.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
Expand All @@ -398,6 +403,7 @@
);
INFOPLIST_FILE = LilyTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kukushi.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -411,6 +417,7 @@
);
INFOPLIST_FILE = LilyTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.kukushi.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand Down
4 changes: 2 additions & 2 deletions Lily/DiskCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public extension Lily {
FileManager.create("\(context)")
}

let writingResult = FileManager.write(data, filename: "\(context)/\(key)")
FileManager.write(data, filename: "\(context)/\(key)")
})
}
}
Expand Down Expand Up @@ -150,7 +150,7 @@ public class ValueProxy {
}
else {
dispatch_async(cacheQueue, { () -> Void in
let path = FileManager.path(filename: "\(self.context)/\(self.key)")
let path = FileManager.path("\(self.context)/\(self.key)")
if let data = NSData(contentsOfFile: path), object: AnyObject = NSKeyedUnarchiver.unarchiveObjectWithData(data) {
dispatch_async(dispatch_get_main_queue(), { () -> Void in
callback(object: object)
Expand Down
78 changes: 43 additions & 35 deletions Lily/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,24 @@ import Foundation

class FileManager {

class func path(#filename: String) -> String {
class func path(filename: String) -> String {
let fileManager = NSFileManager.defaultManager()
let basicURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains:.UserDomainMask).first as! NSURL
let basicURL = fileManager.URLsForDirectory(.DocumentDirectory, inDomains:.UserDomainMask).first!
return basicURL.path! + "/\(filename)"
}

class func create(filename: String) {
let filePath = path(filename: filename)
let filePath = path(filename)
if !fileExistsAtDirectory(filePath) {
NSFileManager.defaultManager().createDirectoryAtPath(filePath, withIntermediateDirectories: false, attributes: nil, error: nil)
do {
try NSFileManager.defaultManager().createDirectoryAtPath(filePath, withIntermediateDirectories: false, attributes: nil)
} catch _ {
}
}
}

class func write(data: NSData, filename: String) -> Bool {
let filePath = path(filename: filename)
let filePath = path(filename)
return data.writeToFile(filePath, atomically: true)
}

Expand All @@ -34,51 +37,56 @@ class FileManager {
}

class func fileExistsAtDirectory(filename: String) -> Bool {
let filePath = path(filename: filename)
let filePath = path(filename)
return NSFileManager.defaultManager().fileExistsAtPath(filePath)
}

class func removeFileAtDirectory(filename: String) -> Bool {
let filePath = path(filename: filename)
return NSFileManager.defaultManager().removeItemAtPath(filePath, error: nil)
let filePath = path(filename)
do {
try NSFileManager.defaultManager().removeItemAtPath(filePath)
return true
} catch _ {
return false
}
}

class func itemsAtDirectory(directoryName: String) -> [AnyObject]? {
let filePath = path(filename: directoryName)
if let URL = NSURL.fileURLWithPath(filePath) {
var error: NSError?
let fileManager = NSFileManager.defaultManager()
if let contents = fileManager.contentsOfDirectoryAtURL(URL, includingPropertiesForKeys: [AnyObject](), options: .SkipsSubdirectoryDescendants, error: &error) as? [NSURL] {

if let theError = error {
println(theError)
let filePath = path(directoryName)
let URL = NSURL.fileURLWithPath(filePath)
let fileManager = NSFileManager.defaultManager()

do {
let contents = try fileManager.contentsOfDirectoryAtURL(URL, includingPropertiesForKeys: [String](), options: .SkipsSubdirectoryDescendants)

var items = [AnyObject]()
for url in contents {
do {
let data = try NSData(contentsOfURL: url, options: .DataReadingMappedIfSafe)
let obj: AnyObject! = NSKeyedUnarchiver.unarchiveObjectWithData(data)
items.append(obj)
} catch let error {
print(error)
return nil
}

var items = [AnyObject]()
for url in contents {
let data = NSData(contentsOfURL: url, options: .DataReadingMappedIfSafe, error: &error)
if let theError = error {
println(theError)
}
else {
let obj: AnyObject! = NSKeyedUnarchiver.unarchiveObjectWithData(data!)
items.append(obj)
}
}
return items
}
return items
} catch let error {
print(error)
return nil
}
return nil
}

class func deleteFile(filename: String, error: NSErrorPointer) -> Bool {
class func deleteFile(filename: String) throws {
let error: NSError! = NSError(domain: "Migrator", code: 0, userInfo: nil)
let fileManager = NSFileManager.defaultManager()
let filePath = path(filename: filename)
if !fileManager.removeItemAtPath(filename, error: error) {
println("\(error)")
return true
do {
try fileManager.removeItemAtPath(filename)
} catch let error1 as NSError {
print("\(error1)")
return
}
return false
throw error
}
}
2 changes: 1 addition & 1 deletion Lily/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.kukushi.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion Lily/Lily.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

/// Some global instance for quick access
/// Global instances for quick access
public let MemoryCache = Lily.shared.memoryCache
public let DiskCache = Lily.shared.diskCache
public let QuickCache = Lily.shared.quickCache
Expand Down
10 changes: 5 additions & 5 deletions Lily/MemoryCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public extension Lily {
/**
subscript with context and key
:param: key the key of cache
:param: context the context of cache
- parameter key: the key of cache
- parameter context: the context of cache
:returns: a cache proxy with named key and context. You don't have to use
- returns: a cache proxy with named key and context. You don't have to use
it directly.
*/
public subscript(key: String, context: String) -> CacheProxy {
Expand Down Expand Up @@ -57,9 +57,9 @@ public extension Lily {
/**
subscript with key only
:param: key the key of cache
- parameter key: the key of cache
:returns: a cache proxy with named key and default context. You don't have to use
- returns: a cache proxy with named key and default context. You don't have to use
it directly
*/
public subscript(key: String) -> CacheProxy {
Expand Down
2 changes: 1 addition & 1 deletion Lily/NSCache+Ex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public extension NSCache {
return keys!
}
set(newValue) {
objc_setAssociatedObject(self, &NSCacheKeysKey, newValue, objc_AssociationPolicy(OBJC_ASSOCIATION_RETAIN))
objc_setAssociatedObject(self, &NSCacheKeysKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Lily/QuickCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public extension Lily {
// MARK: Cache

func cacheToDisk() {
for (_, (_, cache)) in enumerate(memoryCache.caches) {
for (_, (_, cache)) in memoryCache.caches.enumerate() {
for key in cache.allKeys {
if let object: AnyObject = cache[key] {
let data = NSKeyedArchiver.archivedDataWithRootObject(object)
Expand Down
3 changes: 1 addition & 2 deletions LilyTests/DiskCacheTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
// Copyright (c) 2015 kukushi. All rights reserved.
//

import UIKit
import XCTest
import Lily
@testable import Lily

class DiskCacheTest: XCTestCase {

Expand Down
2 changes: 1 addition & 1 deletion LilyTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.kukushi.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
![License](https://img.shields.io/cocoapods/l/Lily.svg?style=flat)
![Platform](https://img.shields.io/cocoapods/p/Lily.svg?style=flat)

Lily is lightweight swift cache framework.
Lily is a lightweight swift cache framework.

## Features

Expand All @@ -26,21 +26,14 @@ pod 'Lily'

### Carthage

[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager for Cocoa application. To install the carthage tool, you can use [Homebrew](http://brew.sh).

```bash
$ brew update
$ brew install carthage
```
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager for Cocoa application.

To integrate Lily into your Xcode project using CocoaPods, specify it in your `Cartfile`:

```ogdl
github "kukushi/Lily" >= 0.1
```

For more information about how to use Carthage, pleasee see its [project page](https://github.com/Carthage/Carthage).

### Manually

It is not recommended to install the framework manually, but if you prefer not to use either of the aforementioned dependency managers, you can integrate Lily into your project manually. A regular way to use Lily in your project would be using Embedded Framework.
Expand Down Expand Up @@ -91,7 +84,7 @@ let poiYou = MemoryCache["poi", "You"].stringValue
## Requirements

* iOS 8.0 or later
* Xcode 6.3 or later
* Xcode 7.0 or later

## License

Expand Down

0 comments on commit 75eb411

Please sign in to comment.