Skip to content

Commit

Permalink
Closes #21 by converting the codebase to Swift 2.0. Some APIs broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
vittoriom committed Aug 22, 2015
1 parent 75d4f74 commit f2018c3
Show file tree
Hide file tree
Showing 54 changed files with 821 additions and 594 deletions.
2 changes: 1 addition & 1 deletion Carlos.playground/Sources/SupportCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public func sharedSubfolder() -> String {
}

public func initializePlayground() {
XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true)
XCPSetExecutionShouldContinueIndefinitely()
}
17 changes: 14 additions & 3 deletions Carlos.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
520863751B64268000F740C7 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5208636C1B64268000F740C7 /* Images.xcassets */; };
520863761B64268000F740C7 /* MemoryWarningSampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5208636D1B64268000F740C7 /* MemoryWarningSampleViewController.swift */; };
520863771B64268000F740C7 /* DataCacheSampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5208636E1B64268000F740C7 /* DataCacheSampleViewController.swift */; };
520863791B64268700F740C7 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 520863781B64268700F740C7 /* Info.plist */; };
5208637E1B64268E00F740C7 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5208637A1B64268E00F740C7 /* LaunchScreen.xib */; };
5208637F1B64268E00F740C7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5208637C1B64268E00F740C7 /* Main.storyboard */; };
520863811B642D4A00F740C7 /* PooledCacheSampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 520863801B642D4A00F740C7 /* PooledCacheSampleViewController.swift */; };
520863831B6430C600F740C7 /* CappedRequestCacheSampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 520863821B6430C600F740C7 /* CappedRequestCacheSampleViewController.swift */; };
520863851B64314400F740C7 /* DelayedNetworkFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 520863841B64314400F740C7 /* DelayedNetworkFetcher.swift */; };
522A4E6B1B7BDACB00646D52 /* ImageCacheSampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522A4E6A1B7BDACB00646D52 /* ImageCacheSampleViewController.swift */; };
523033E11B890247001489F3 /* ExtractErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523033D51B8901B6001489F3 /* ExtractErrorTests.swift */; };
523257D21B51993000A10A56 /* TwoWayTransformationBoxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523257D11B51993000A10A56 /* TwoWayTransformationBoxTests.swift */; };
523257D41B519AB900A10A56 /* OneWayTransformationBoxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 523257D31B519AB900A10A56 /* OneWayTransformationBoxTests.swift */; };
5243C4B31B77670F00737B3B /* StringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5243C4B21B77670F00737B3B /* StringConvertible.swift */; };
Expand Down Expand Up @@ -200,6 +200,7 @@
520863821B6430C600F740C7 /* CappedRequestCacheSampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CappedRequestCacheSampleViewController.swift; sourceTree = "<group>"; };
520863841B64314400F740C7 /* DelayedNetworkFetcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DelayedNetworkFetcher.swift; sourceTree = "<group>"; };
522A4E6A1B7BDACB00646D52 /* ImageCacheSampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCacheSampleViewController.swift; sourceTree = "<group>"; };
523033D51B8901B6001489F3 /* ExtractErrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExtractErrorTests.swift; sourceTree = "<group>"; };
523257D11B51993000A10A56 /* TwoWayTransformationBoxTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoWayTransformationBoxTests.swift; sourceTree = "<group>"; };
523257D31B519AB900A10A56 /* OneWayTransformationBoxTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OneWayTransformationBoxTests.swift; sourceTree = "<group>"; };
5243C4B21B77670F00737B3B /* StringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringConvertible.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -366,6 +367,7 @@
52E6E24B1B5C02EA00C3DF6C /* DeferredCacheRequestOperationTests.swift */,
5243C4BE1B77686300737B3B /* StringConvertibleTests.swift */,
527C65521B7A89440005023B /* SwitchCacheTests.swift */,
523033D51B8901B6001489F3 /* ExtractErrorTests.swift */,
);
name = CarlosTests;
path = Tests;
Expand Down Expand Up @@ -553,7 +555,9 @@
AD695CD71B46CD65004E998D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0630;
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = WeltN24;
TargetAttributes = {
52635A1C1B4F0F3D00F187EE = {
Expand Down Expand Up @@ -689,7 +693,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
520863791B64268700F740C7 /* Info.plist in Resources */,
5208637E1B64268E00F740C7 /* LaunchScreen.xib in Resources */,
520863751B64268000F740C7 /* Images.xcassets in Resources */,
5208637F1B64268E00F740C7 /* Main.storyboard in Resources */,
Expand Down Expand Up @@ -742,6 +745,7 @@
526339891B52B51C00074CB9 /* DiskCacheTests.swift in Sources */,
52F064551B51B26200145C98 /* MKDistanceFormatterTransformerTests.swift in Sources */,
523257D41B519AB900A10A56 /* OneWayTransformationBoxTests.swift in Sources */,
523033E11B890247001489F3 /* ExtractErrorTests.swift in Sources */,
527C65531B7A89440005023B /* SwitchCacheTests.swift in Sources */,
526339941B52BC6D00074CB9 /* Crypto.swift in Sources */,
5253F3D91B57D7DD0035B1FB /* RequestCapperCacheTests.swift in Sources */,
Expand Down Expand Up @@ -833,6 +837,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
ONLY_ACTIVE_ARCH = NO;
PRODUCT_BUNDLE_IDENTIFIER = "de.weltn24.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -852,6 +857,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.weltn24.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -874,6 +880,7 @@
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.weltn24.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
Expand All @@ -890,6 +897,7 @@
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.4;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.weltn24.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand All @@ -915,6 +923,7 @@
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -987,6 +996,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = "de.weltn24.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
Expand All @@ -1001,6 +1011,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
OTHER_SWIFT_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = "de.weltn24.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand Down
13 changes: 8 additions & 5 deletions Carlos.xcodeproj/xcshareddata/xcschemes/Carlos.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:Carlos.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
Expand All @@ -85,10 +88,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
Expand Down
13 changes: 8 additions & 5 deletions Carlos.xcodeproj/xcshareddata/xcschemes/CarlosSample.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0640"
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
Expand All @@ -52,15 +52,18 @@
ReferencedContainer = "container:Carlos.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand All @@ -76,10 +79,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
16 changes: 8 additions & 8 deletions Carlos/BasicCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public final class BasicCache<A, B>: CacheLevel {
/**
Initializes a new instance of a BasicCache specifying closures for get, set, clear and onMemoryWarning, thus determining the behavior of the cache level as a whole
:param: getClosure The closure to execute when you call get(key) on this instance
:param: setClosure The closure to execute when you call set(value, key) on this instance
:param: clearClosure The closure to execute when you call clear() on this instance
:param: memoryClosure The closure to execute when you call onMemoryWarning() on this instance, or when a memory warning is thrown by the system and the cache level is listening for memory pressure events
- parameter getClosure: The closure to execute when you call get(key) on this instance
- parameter setClosure: The closure to execute when you call set(value, key) on this instance
- parameter clearClosure: The closure to execute when you call clear() on this instance
- parameter memoryClosure: The closure to execute when you call onMemoryWarning() on this instance, or when a memory warning is thrown by the system and the cache level is listening for memory pressure events
*/
public init(getClosure: (key: A) -> CacheRequest<B>, setClosure: (key: A, value: B) -> Void, clearClosure: () -> Void, memoryClosure: () -> Void) {
self.getClosure = getClosure
Expand All @@ -28,9 +28,9 @@ public final class BasicCache<A, B>: CacheLevel {
/**
Asks the cache to get the value for a given key
:param: key The key you want to get the value for
- parameter key: The key you want to get the value for
:returns: The result of the getClosure specified when initializing the instance
- returns: The result of the getClosure specified when initializing the instance
*/
public func get(key: KeyType) -> CacheRequest<OutputType> {
return getClosure(key: key)
Expand All @@ -39,8 +39,8 @@ public final class BasicCache<A, B>: CacheLevel {
/**
Asks the cache to set a value for the given key
:param: value The value to set on the cache
:param: key The key to use for the given value
- parameter value: The value to set on the cache
- parameter key: The key to use for the given value
:discussion: This call executes the setClosure specified when initializing the instance
*/
Expand Down
8 changes: 4 additions & 4 deletions Carlos/CacheProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ A simple class with the purpose of providing standard caches
*/
public class CacheProvider {
/**
:returns: An initialized and configured CacheLevel that takes NSURL keys and stores NSData values. Network requests are pooled for efficiency
- returns: An initialized and configured CacheLevel that takes NSURL keys and stores NSData values. Network requests are pooled for efficiency
*/
public static func dataCache() -> BasicCache<NSURL, NSData> {
return MemoryCacheLevel() >>> DiskCacheLevel() >>> pooled(NetworkFetcher())
return MemoryCacheLevel() >>> DiskCacheLevel() >>> NetworkFetcher().pooled()
}

/**
:returns: An initialized and configured CacheLevel that takes NSURL keys and stores UIImage values. Network requests are pooled for efficiency.
- returns: An initialized and configured CacheLevel that takes NSURL keys and stores UIImage values. Network requests are pooled for efficiency.
:discussion: The code is not safe at the moment. This means if you try to store in this cache something that is not a UIImage (e.g. a NSURL pointing to a JSON or an HTML document), the app will crash (this will be fixed in a future release)
*/
public static func imageCache() -> BasicCache<NSURL, UIImage> {
return MemoryCacheLevel() >>> DiskCacheLevel() >>> (pooled(NetworkFetcher()) =>> TwoWayTransformationBox<NSData, UIImage>(transform: { UIImage(data: $0) }, inverseTransform: { UIImagePNGRepresentation($0) /* This is a waste of bytes, we should probably use a lower-level framework */ }))
return MemoryCacheLevel() >>> DiskCacheLevel() >>> (NetworkFetcher().pooled() =>> TwoWayTransformationBox<NSData, UIImage>(transform: { UIImage(data: $0) }, inverseTransform: { UIImagePNGRepresentation($0) /* This is a waste of bytes, we should probably use a lower-level framework */ }))
}
}
Loading

0 comments on commit f2018c3

Please sign in to comment.