diff --git a/cokit/Examples/coKitExamples/Podfile b/cokit/Examples/coKitExamples/Podfile index 6f095d0..488af5d 100644 --- a/cokit/Examples/coKitExamples/Podfile +++ b/cokit/Examples/coKitExamples/Podfile @@ -5,6 +5,7 @@ target 'coKitExamples' do pod 'cokit', :path => '../../../' pod 'coobjc', :path => '../../../' + pod 'cocore', :path => '../../../' end @@ -12,6 +13,8 @@ target 'coKitExamplesTests' do pod 'cokit', :path => '../../../' pod 'coobjc', :path => '../../../' + pod 'cocore', :path => '../../../' + pod 'Specta', '~> 1.0' pod 'Expecta', '~> 1.0' # expecta matchers diff --git a/cokit/Examples/coKitExamples/coKitExamples.xcodeproj/project.pbxproj b/cokit/Examples/coKitExamples/coKitExamples.xcodeproj/project.pbxproj index 41e8b69..81ad3e4 100644 --- a/cokit/Examples/coKitExamples/coKitExamples.xcodeproj/project.pbxproj +++ b/cokit/Examples/coKitExamples/coKitExamples.xcodeproj/project.pbxproj @@ -28,6 +28,9 @@ 184C4DC221D3183800C94113 /* coKitURLConnectionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 184C4DC121D3183800C94113 /* coKitURLConnectionTests.m */; }; 184C4DC421D3184800C94113 /* coKitURLSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 184C4DC321D3184800C94113 /* coKitURLSession.m */; }; 184C4DC621D3185700C94113 /* coKitUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 184C4DC521D3185700C94113 /* coKitUserDefaults.m */; }; + 1851C7142283FDA6008342C0 /* home2@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1851C7112283FDA6008342C0 /* home2@3x.png */; }; + 1851C7152283FDA6008342C0 /* home1@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1851C7122283FDA6008342C0 /* home1@2x.png */; }; + 1851C7162283FDA6008342C0 /* home.png in Resources */ = {isa = PBXBuildFile; fileRef = 1851C7132283FDA6008342C0 /* home.png */; }; 18C43A3E21D1D4C300D75A9B /* DemoListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18C43A3D21D1D4C300D75A9B /* DemoListViewController.m */; }; 18C43A4221D1D4E500D75A9B /* AlertDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 18C43A4021D1D4E500D75A9B /* AlertDemoViewController.m */; }; 18C43A4321D1D4E500D75A9B /* AlertDemoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 18C43A4121D1D4E500D75A9B /* AlertDemoViewController.xib */; }; @@ -76,6 +79,9 @@ 184C4DC121D3183800C94113 /* coKitURLConnectionTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = coKitURLConnectionTests.m; sourceTree = ""; }; 184C4DC321D3184800C94113 /* coKitURLSession.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = coKitURLSession.m; sourceTree = ""; }; 184C4DC521D3185700C94113 /* coKitUserDefaults.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = coKitUserDefaults.m; sourceTree = ""; }; + 1851C7112283FDA6008342C0 /* home2@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "home2@3x.png"; sourceTree = ""; }; + 1851C7122283FDA6008342C0 /* home1@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "home1@2x.png"; sourceTree = ""; }; + 1851C7132283FDA6008342C0 /* home.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = home.png; sourceTree = ""; }; 18C43A3C21D1D4C300D75A9B /* DemoListViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DemoListViewController.h; sourceTree = ""; }; 18C43A3D21D1D4C300D75A9B /* DemoListViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DemoListViewController.m; sourceTree = ""; }; 18C43A3F21D1D4E500D75A9B /* AlertDemoViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AlertDemoViewController.h; sourceTree = ""; }; @@ -180,6 +186,9 @@ 183F72C421C9E9D10041C32B /* Resources */ = { isa = PBXGroup; children = ( + 1851C7132283FDA6008342C0 /* home.png */, + 1851C7122283FDA6008342C0 /* home1@2x.png */, + 1851C7112283FDA6008342C0 /* home2@3x.png */, 183F72C521C9E9DE0041C32B /* test.json */, ); path = Resources; @@ -217,8 +226,6 @@ 183F728A21C8E8890041C32B /* Sources */, 183F728B21C8E8890041C32B /* Frameworks */, 183F728C21C8E8890041C32B /* Resources */, - 24A92622A4331EE56ABFE7D5 /* [CP] Embed Pods Frameworks */, - BF68B3A67305FACEED8A7FCA /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -237,8 +244,6 @@ 183F72A221C8E88C0041C32B /* Sources */, 183F72A321C8E88C0041C32B /* Frameworks */, 183F72A421C8E88C0041C32B /* Resources */, - CB2CC9A54B12823E5E21B0EB /* [CP] Embed Pods Frameworks */, - 866D6F23B88BC4316C965F2A /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -294,8 +299,11 @@ files = ( 183F729E21C8E88B0041C32B /* LaunchScreen.storyboard in Resources */, 18C43A4821D1D4F500D75A9B /* ImagePickerDemoViewController.xib in Resources */, + 1851C7162283FDA6008342C0 /* home.png in Resources */, 183F72C621C9E9DE0041C32B /* test.json in Resources */, + 1851C7152283FDA6008342C0 /* home1@2x.png in Resources */, 183F729B21C8E88B0041C32B /* Assets.xcassets in Resources */, + 1851C7142283FDA6008342C0 /* home2@3x.png in Resources */, 183F729921C8E8890041C32B /* Main.storyboard in Resources */, 18C43A4321D1D4E500D75A9B /* AlertDemoViewController.xib in Resources */, ); @@ -317,28 +325,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-coKitExamplesTests-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; - 24A92622A4331EE56ABFE7D5 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-coKitExamples/Pods-coKitExamples-frameworks.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; 66A9FC6F6F04E954F19CFE67 /* [CP] Check Pods Manifest.lock */ = { @@ -347,58 +343,16 @@ files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-coKitExamples-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; - 866D6F23B88BC4316C965F2A /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-coKitExamplesTests/Pods-coKitExamplesTests-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - BF68B3A67305FACEED8A7FCA /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-coKitExamples/Pods-coKitExamples-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - CB2CC9A54B12823E5E21B0EB /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-coKitExamplesTests/Pods-coKitExamplesTests-frameworks.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ diff --git a/cokit/Examples/coKitExamples/coKitExamples.xcodeproj/xcshareddata/xcschemes/coKitExamples.xcscheme b/cokit/Examples/coKitExamples/coKitExamples.xcodeproj/xcshareddata/xcschemes/coKitExamples.xcscheme new file mode 100644 index 0000000..6ae89e7 --- /dev/null +++ b/cokit/Examples/coKitExamples/coKitExamples.xcodeproj/xcshareddata/xcschemes/coKitExamples.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cokit/Examples/coKitExamples/coKitExamples.xcodeproj/xcshareddata/xcschemes/coKitExamplesTests.xcscheme b/cokit/Examples/coKitExamples/coKitExamples.xcodeproj/xcshareddata/xcschemes/coKitExamplesTests.xcscheme new file mode 100644 index 0000000..a6c03dd --- /dev/null +++ b/cokit/Examples/coKitExamples/coKitExamples.xcodeproj/xcshareddata/xcschemes/coKitExamplesTests.xcscheme @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cokit/Examples/coKitExamples/coKitExamples/Resources/home.png b/cokit/Examples/coKitExamples/coKitExamples/Resources/home.png new file mode 100644 index 0000000..9b4cfc6 Binary files /dev/null and b/cokit/Examples/coKitExamples/coKitExamples/Resources/home.png differ diff --git a/cokit/Examples/coKitExamples/coKitExamples/Resources/home1@2x.png b/cokit/Examples/coKitExamples/coKitExamples/Resources/home1@2x.png new file mode 100644 index 0000000..9b4cfc6 Binary files /dev/null and b/cokit/Examples/coKitExamples/coKitExamples/Resources/home1@2x.png differ diff --git a/cokit/Examples/coKitExamples/coKitExamples/Resources/home2@3x.png b/cokit/Examples/coKitExamples/coKitExamples/Resources/home2@3x.png new file mode 100644 index 0000000..a36ee53 Binary files /dev/null and b/cokit/Examples/coKitExamples/coKitExamples/Resources/home2@3x.png differ diff --git a/cokit/Examples/coKitExamples/coKitExamplesTests/coKitExamplesTests.m b/cokit/Examples/coKitExamples/coKitExamplesTests/coKitExamplesTests.m index 02fded6..1abe6b9 100644 --- a/cokit/Examples/coKitExamples/coKitExamplesTests/coKitExamplesTests.m +++ b/cokit/Examples/coKitExamples/coKitExamplesTests/coKitExamplesTests.m @@ -17,6 +17,8 @@ // limitations under the License. #import +#import +#import @interface coKitExamplesTests : XCTestCase @@ -37,6 +39,38 @@ - (void)tearDown { - (void)testExample { // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct results. + XCTestExpectation *e = [self expectationWithDescription:@"test"]; + co_launch(^{ + UIImage *image = await([UIImage async_imageWithContentsOfFileNamed:@"home"]); + NSAssert(image != nil, @"test"); + + image = await([UIImage async_imageWithContentsOfFileNamed:@"home1"]); + NSAssert(image != nil, @"test1"); + + image = await([UIImage async_imageWithContentsOfFileNamed:@"home2"]); + NSAssert(image != nil, @"test2"); + + image = await([UIImage async_imageWithContentsOfFileNamed:@"home.png"]); + NSAssert(image != nil, @"test"); + + image = await([UIImage async_imageWithContentsOfFileNamed:@"home1.png"]); + NSAssert(image != nil, @"test1"); + + image = await([UIImage async_imageWithContentsOfFileNamed:@"home2.png"]); + NSAssert(image != nil, @"test2"); + + image = await([UIImage async_imageWithContentsOfFileNamed:@"home@2x.png"]); + NSAssert(image == nil, @"test"); + + image = await([UIImage async_imageWithContentsOfFileNamed:@"home1@3x.png"]); + NSAssert(image == nil, @"test1"); + + image = await([UIImage async_imageWithContentsOfFileNamed:@"home2@2x.png"]); + NSAssert(image == nil, @"test2"); + [e fulfill]; + }); + + [self waitForExpectations:@[e] timeout:10]; } - (void)testPerformanceExample { diff --git a/cokit/Examples/coKitExamples/coKitExamplesTests/coKitXMLParserTests.m b/cokit/Examples/coKitExamples/coKitExamplesTests/coKitXMLParserTests.m index 8b9de6b..10a87c0 100644 --- a/cokit/Examples/coKitExamples/coKitExamplesTests/coKitXMLParserTests.m +++ b/cokit/Examples/coKitExamples/coKitExamplesTests/coKitXMLParserTests.m @@ -57,7 +57,7 @@ - (void)testXMLParse{ int testsuiteCount = 0; int testcaseCount = 0; while (1) { - item = [parse_generator next]; +// item = [parse_generator next]; if (item.itemType == COXMLItemDidStartElement) { if ([item.elementName isEqualToString:@"testsuites"]) { testsuitesCount++; diff --git a/cokit/cokit/UIKit/UIImage+Coroutine.h b/cokit/cokit/UIKit/UIImage+Coroutine.h index 9beaaba..b09aa12 100644 --- a/cokit/cokit/UIKit/UIImage+Coroutine.h +++ b/cokit/cokit/UIKit/UIImage+Coroutine.h @@ -28,10 +28,13 @@ NS_ASSUME_NONNULL_BEGIN + (COPromise*)async_imageNamed:(NSString *)name inBundle:(nullable NSBundle *)bundle compatibleWithTraitCollection:(nullable UITraitCollection *)traitCollection NS_AVAILABLE_IOS(8_0); #endif ++ (COPromise*)async_imageWithContentsOfFileNamed:(NSString *)imageName; + + (COPromise*)async_imageWithContentsOfFile:(NSString *)path; + (COPromise*)async_imageWithData:(NSData *)data; + (COPromise*)async_imageWithData:(NSData *)data scale:(CGFloat)scale NS_AVAILABLE_IOS(6_0); +- (COPromise*)async_initWithContentsOfFileNamed:(NSString *)imageName; - (COPromise*)async_initWithContentsOfFile:(NSString *)path; - (COPromise*)async_initWithData:(NSData *)data; - (COPromise*)async_initWithData:(NSData *)data scale:(CGFloat)scale NS_AVAILABLE_IOS(6_0); @@ -44,11 +47,14 @@ NS_ASSUME_NONNULL_BEGIN #if __has_include() + (UIImage *)co_imageNamed:(NSString *)name inBundle:(nullable NSBundle *)bundle compatibleWithTraitCollection:(nullable UITraitCollection *)traitCollection NS_AVAILABLE_IOS(8_0); #endif ++ (UIImage *)co_imageWithContentsOfFileNamed:(NSString *)imageName; + (UIImage *)co_imageWithContentsOfFile:(NSString *)path; + (UIImage *)co_imageWithData:(NSData *)data; + (UIImage *)co_imageWithData:(NSData *)data scale:(CGFloat)scale NS_AVAILABLE_IOS(6_0); +- (UIImage *)co_initWithContentsOfFileNamed:(NSString *)imageName; + - (UIImage *)co_initWithContentsOfFile:(NSString *)path; - (UIImage *)co_initWithData:(NSData *)data; - (UIImage *)co_initWithData:(NSData *)data scale:(CGFloat)scale NS_AVAILABLE_IOS(6_0); diff --git a/cokit/cokit/UIKit/UIImage+Coroutine.m b/cokit/cokit/UIKit/UIImage+Coroutine.m index f933b69..218f0f8 100644 --- a/cokit/cokit/UIKit/UIImage+Coroutine.m +++ b/cokit/cokit/UIKit/UIImage+Coroutine.m @@ -42,6 +42,15 @@ + (UIImage *)co_imageNamed:(NSString *)name inBundle:(NSBundle *)bundle compatib } #endif ++ (UIImage *)co_imageWithContentsOfFileNamed:(NSString *)imageName{ + if ([COCoroutine currentCoroutine]) { + return await([self async_imageWithContentsOfFileNamed:imageName]); + } + else{ + return nil; + } +} + + (UIImage *)co_imageWithContentsOfFile:(NSString *)path{ if ([COCoroutine currentCoroutine]) { return await([self async_imageWithContentsOfFile:path]); @@ -69,6 +78,13 @@ + (UIImage *)co_imageWithData:(NSData *)data scale:(CGFloat)scale{ } } +- (UIImage *)co_initWithContentsOfFileNamed:(NSString *)imageName{ + if ([COCoroutine currentCoroutine]) { + return await([self async_initWithContentsOfFileNamed:imageName]); + } + return nil; +} + - (UIImage *)co_initWithContentsOfFile:(NSString *)path{ if ([COCoroutine currentCoroutine]) { return await([self async_initWithContentsOfFile:path]); @@ -131,6 +147,12 @@ @implementation UIImage (COPromise) } #endif ++ (COPromise*)async_imageWithContentsOfFileNamed:(NSString *)imageName{ + return [[self alloc] async_initWithContentsOfFileNamed:imageName]; +} + + + + (COPromise*)async_imageWithContentsOfFile:(NSString *)path{ return [COPromise promise:^(COPromiseFulfill _Nonnull resolve, COPromiseReject _Nonnull reject) { [COKitCommon runBlock:^{ @@ -171,6 +193,63 @@ @implementation UIImage (COPromise) }]; } +- (COPromise *)async_initWithContentsOfFileNamed:(NSString *)imageName{ + return [COPromise promise:^(COPromiseFulfill _Nonnull resolve, COPromiseReject _Nonnull reject) { + [COKitCommon runBlock:^{ + if (imageName.length <= 0) { + resolve(nil); + return; + } + NSArray *list = [imageName componentsSeparatedByString:@"."]; + + NSString *type = nil; + NSString *suffix = nil; + NSString *fileName = list.firstObject; + if (list.count >= 2) { + type = list.lastObject; + } + if ([fileName hasPrefix:@"@2x"]) { + suffix = @"@2x"; + fileName = [fileName stringByReplacingOccurrencesOfString:@"@2x" withString:@""]; + } + if ([fileName hasPrefix:@"@3x"]) { + suffix = @"@3x"; + fileName = [fileName stringByReplacingOccurrencesOfString:@"@3x" withString:@""]; + } + NSArray *typeList = @[@"png", @"jpg"]; + NSArray *suffixList = @[@"", @"@2x", @"@3x"]; + if (type.length > 0) { + typeList = @[type]; + } + if (suffix.length > 0) { + suffixList = @[@"", suffix]; + } + + NSString *filePath = nil; + + for (NSString *s in suffixList) { + for (NSString *t in typeList) { + NSString *f = [NSString stringWithFormat:@"%@%@", fileName, s]; + filePath = [[NSBundle mainBundle] pathForResource:f ofType:t]; + if (filePath) { + break; + } + } + if (filePath) { + break; + } + } + UIImage *image = [self initWithContentsOfFile:filePath]; + if (image) { + resolve(image); + } + else{ + resolve(nil); + } + } onQueue:[COKitCommon image_queue]]; + }]; +} + - (COPromise*)async_initWithContentsOfFile:(NSString *)path{ return [COPromise promise:^(COPromiseFulfill _Nonnull resolve, COPromiseReject _Nonnull reject) { [COKitCommon runBlock:^{