Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit 3ffa4d2

Browse files
committed
Merge remote-tracking branch 'bor9brest/extensions' into develop, fix podspec, fix color extension
2 parents affff42 + 3c2bc18 commit 3ffa4d2

5 files changed

Lines changed: 134 additions & 17 deletions

File tree

Example/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ PODS:
44
- OrangeFramework/Dependency (= 0.1.0)
55
- OrangeFramework/Extensions (= 0.1.0)
66
- OrangeFramework/Log (= 0.1.0)
7-
- OrangeFramework/Segue (= 0.1.0)
7+
- OrangeFramework/Segues (= 0.1.0)
88
- OrangeFramework/SystemInfo (= 0.1.0)
99
- OrangeFramework/Dependency (0.1.0)
1010
- OrangeFramework/Extensions (0.1.0)
1111
- OrangeFramework/Log (0.1.0)
12-
- OrangeFramework/Segue (0.1.0)
12+
- OrangeFramework/Segues (0.1.0)
1313
- OrangeFramework/SystemInfo (0.1.0)
1414
- Quick (0.8.0)
1515

@@ -24,7 +24,7 @@ EXTERNAL SOURCES:
2424

2525
SPEC CHECKSUMS:
2626
Nimble: 4c353d43735b38b545cbb4cb91504588eb5de926
27-
OrangeFramework: eefc467b5f89a9ddf78c220ac219030e9b57d0e5
27+
OrangeFramework: 70e205c80d395612b596617ea661f06e10f9bf6a
2828
Quick: 563d0f6ec5f72e394645adb377708639b7dd38ab
2929

3030
COCOAPODS: 0.39.0

Example/Specs/OFExtensionSpec.m

Lines changed: 119 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,128 @@
55
QuickSpecBegin(OFExtensionSpec)
66

77
describe(@"NSBlockOperation+AsyncBlock", ^{
8-
9-
})
8+
context(@"when use serial queue", ^{
9+
it(@"run async operation in series", ^{
10+
__block NSString *testString = @"";
11+
NSOperationQueue *testOperationQueue = [[NSOperationQueue alloc]init];
12+
testOperationQueue.maxConcurrentOperationCount = 1;
13+
[testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) {
14+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
15+
testString = [testString stringByAppendingString:@"1"];
16+
finish();
17+
});
18+
}];
19+
[testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) {
20+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
21+
testString = [testString stringByAppendingString:@"2"];
22+
finish();
23+
});
24+
}];
25+
[testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) {
26+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
27+
testString = [testString stringByAppendingString:@"3"];
28+
finish();
29+
});
30+
}];
31+
expect(testString).toEventually(equal(@"123"));
32+
});
33+
});
34+
context(@"when use parallel queue", ^{
35+
it(@"run async operation in parallel", ^{
36+
__block NSString *testString = @"";
37+
NSOperationQueue *testOperationQueue = [[NSOperationQueue alloc]init];
38+
testOperationQueue.maxConcurrentOperationCount = 3;
39+
[testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) {
40+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
41+
testString = [testString stringByAppendingString:@"1"];
42+
finish();
43+
});
44+
}];
45+
[testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) {
46+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
47+
testString = [testString stringByAppendingString:@"2"];
48+
finish();
49+
});
50+
}];
51+
[testOperationQueue addOperationWithAsyncBlock:^(OFAsyncBlockFinish _Nonnull finish) {
52+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
53+
testString = [testString stringByAppendingString:@"3"];
54+
finish();
55+
});
56+
}];
57+
expect(testString).toEventually(equal(@"132"));
58+
});
59+
});
60+
});
1061

1162
describe(@"NSString+Regex", ^{
12-
13-
})
63+
context(@"when the string contains regex pattern", ^{
64+
NSString *testString = @"This is test string.";
65+
it(@"match regex", ^{
66+
NSString *testRegex = @".*";
67+
expect(@([testString matchRegex:testRegex])).to(beTrue());
68+
});
69+
70+
it(@"has first match of regex", ^{
71+
NSString *testRegex = @"is";
72+
expect([testString firstMatchOfRegex:testRegex]).toNot(beNil());
73+
});
74+
75+
it(@"has all matches of regex", ^{
76+
NSString *testRegex = @"is";
77+
NSInteger resultCount = 2;
78+
expect(@([testString allMatchesOfRegex:testRegex].count)).to(equal(@(resultCount)));
79+
});
80+
81+
it(@"has match email", ^{
82+
NSString *testEmail = @"test@mail.com";
83+
expect(@([testEmail matchEmailString])).to(beTrue());
84+
});
85+
});
86+
context(@"when the string NOT contains regex pattern", ^{
87+
NSString *testString = @"This is test string.";
88+
it(@"not match regex", ^{
89+
NSString *testRegex = @"This";
90+
expect(@([testString matchRegex:testRegex])).toNot(beTrue());
91+
});
92+
it(@"has not first match of regex", ^{
93+
NSString *testRegex = @"testing";
94+
expect([testString firstMatchOfRegex:testRegex]).to(beNil());
95+
});
96+
97+
it(@"has not all matches of regex", ^{
98+
NSString *testRegex = @"testing";
99+
expect([testString firstMatchOfRegex:testRegex]).to(beNil());
100+
});
101+
102+
it(@"has not match email", ^{
103+
NSString *testEmail = @"testmail.com";
104+
expect(@([testEmail matchEmailString])).toNot(beTrue());
105+
});
106+
});
107+
});
14108

15109
describe(@"UIColor+HexString", ^{
16-
17-
})
110+
context(@"when valid hex string", ^{
111+
it(@"create color", ^{
112+
NSString *testStringColor = @"#e74c3c";
113+
CGFloat testR = 231/256.0f, testG = 76/256.0f, testB = 60/256.0f;
114+
UIColor *testColor = [UIColor colorWithHexString:testStringColor];
115+
CGFloat r, g, b;
116+
[testColor getRed:&r green:&g blue:&b alpha:NULL];
117+
expect(@(r)).to(equal(@(testR)));
118+
expect(@(g)).to(equal(@(testG)));
119+
expect(@(b)).to(equal(@(testB)));
120+
});
121+
context(@"when NOT valid hex string", ^{
122+
it(@"create NIL color", ^{
123+
NSString *testStringColor = @"888e74c3c";
124+
expect([UIColor colorWithHexString:testStringColor]).to(beNil());
125+
});
126+
});
127+
128+
});
129+
});
18130

19131
QuickSpecEnd
132+

OrangeFramework.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Pod::Spec.new do |s|
77
s.name = "OrangeFramework"
88
s.version = "0.1.0"
9-
s.summary = "Powerful framework aimed at fast and high quality developing mobile apps on Objective-C and Swift.
9+
s.summary = "Powerful framework aimed at fast and high quality developing mobile apps on Objective-C and Swift."
1010
s.description = <<-DESC
1111
OrangeFramework is a collection of components for fast and high quality developing mobile apps on Objective-C and Swift.
1212
It includes a light-weight iOC container (used for dependency injection), flexible logger, powerful extensions and simple system info getter.

OrangeFramework/Extensions/UIKit/UIColor+OFExtension.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ NS_ASSUME_NONNULL_BEGIN
77
+ (instancetype)colorWith8BitRed:(NSUInteger)red green:(NSUInteger)green blue:(NSUInteger)blue NS_SWIFT_UNAVAILABLE("Use swift init instead");
88
+ (instancetype)colorWith8BitRed:(NSUInteger)red green:(NSUInteger)green blue:(NSUInteger)blue alpha:(CGFloat)alpha NS_SWIFT_UNAVAILABLE("Use swift init instead");
99

10-
+ (instancetype)colorWithHexString:(NSString *)hexString;
11-
+ (instancetype)colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha;
10+
+ (nullable instancetype)colorWithHexString:(NSString *)hexString;
11+
+ (nullable instancetype)colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha;
1212

1313
@end
1414

OrangeFramework/Extensions/UIKit/UIColor+OFExtension.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ + (instancetype)colorWithHexString:(NSString *)hexString {
1515
}
1616

1717
+ (instancetype)colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha {
18-
unsigned rgbValue = 0;
19-
NSScanner *scanner = [NSScanner scannerWithString:hexString];
20-
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"#"]];
21-
[scanner scanHexInt:&rgbValue];
22-
return [self colorWith8BitRed:(rgbValue & 0xFF0000) >> 16 green:(rgbValue & 0xFF00) >> 8 blue:rgbValue & 0xFF alpha:alpha];
18+
NSString *cleanedHexString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
19+
if (cleanedHexString.length == 6) {
20+
NSScanner *scanner = [NSScanner scannerWithString:cleanedHexString];
21+
unsigned rgbValue = 0;
22+
if ([scanner scanHexInt:&rgbValue]) {
23+
return [self colorWith8BitRed:(rgbValue & 0xFF0000) >> 16 green:(rgbValue & 0xFF00) >> 8 blue:rgbValue & 0xFF alpha:alpha];
24+
}
25+
}
26+
return nil;
2327
}
2428

2529
@end

0 commit comments

Comments
 (0)