File tree Expand file tree Collapse file tree 2 files changed +18
-25
lines changed Expand file tree Collapse file tree 2 files changed +18
-25
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,7 @@ open class ImageDrawer {
120
120
121
121
// MARK: Cache
122
122
123
+ private static let lock : NSLock = NSLock ( )
123
124
private static var cachedImages = [ String: UIImage] ( )
124
125
private var cacheKey : String {
125
126
var attributes = [ String: String] ( )
@@ -267,8 +268,10 @@ open class ImageDrawer {
267
268
}
268
269
269
270
private func imageWithSize( _ size: CGSize , useCache: Bool = true ) -> UIImage {
270
- if let cachedImage = type ( of: self ) . cachedImages [ self . cacheKey] , useCache {
271
- return cachedImage
271
+ if useCache {
272
+ if let cachedImage = type ( of: self ) . cachedImages [ self . cacheKey] {
273
+ return cachedImage
274
+ }
272
275
}
273
276
274
277
var imageSize = CGSize ( width: size. width, height: size. height)
@@ -448,7 +451,9 @@ open class ImageDrawer {
448
451
}
449
452
450
453
if useCache {
451
- type ( of: self ) . cachedImages [ self . cacheKey] = image
454
+ ImageDrawer . lock. lock ( )
455
+ ImageDrawer . cachedImages [ self . cacheKey] = image
456
+ ImageDrawer . lock. unlock ( )
452
457
}
453
458
454
459
return image
Original file line number Diff line number Diff line change 8
8
9
9
import UIKit
10
10
import XCTest
11
+ import SwiftyImage
11
12
12
13
class SwiftyImageTests : XCTestCase {
13
-
14
- override func setUp( ) {
15
- super. setUp ( )
16
- // Put setup code here. This method is called before the invocation of each test method in the class.
14
+ func testCacheLock( ) {
15
+ for _ in 0 ..< 100 {
16
+ DispatchQueue . global ( ) . async {
17
+ _ = UIImage . resizable ( ) . border ( width: 1 ) . corner ( radius: 15 ) . image
18
+ }
17
19
}
18
-
19
- override func tearDown( ) {
20
- // Put teardown code here. This method is called after the invocation of each test method in the class.
21
- super. tearDown ( )
22
- }
23
-
24
- func testExample( ) {
25
- // This is an example of a functional test case.
26
- XCTAssert ( true , " Pass " )
27
- }
28
-
29
- func testPerformanceExample( ) {
30
- // This is an example of a performance test case.
31
- self . measure ( ) {
32
- // Put the code you want to measure the time of here.
33
- }
34
- }
35
-
20
+
21
+ let expectation = XCTestExpectation ( )
22
+ XCTWaiter ( ) . wait ( for: [ expectation] , timeout: 1 )
23
+ }
36
24
}
You can’t perform that action at this time.
0 commit comments