Skip to content

Commit 2bbb190

Browse files
authored
Merge pull request #26 from Liftric/fix/memory-leaks
Fix: memory leaks
2 parents f5e9d41 + 94b2c31 commit 2bbb190

File tree

11 files changed

+271
-307
lines changed

11 files changed

+271
-307
lines changed

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,26 @@ sourceSets {
2323
#### Android
2424

2525
```kotlin
26-
val store = KVault(context = Context)
26+
val store = KVault(context)
2727
```
2828

2929
#### iOS
3030

3131
```kotlin
32-
val store = KVault(serviceName = "credentials", accessGroup = null)
32+
val store = KVault(serviceName = null, accessGroup = null)
3333
```
3434

35+
| Parameter | Description |
36+
| :----------- | :---------------------------------- |
37+
| serviceName | Used to categories objects. |
38+
| accessGroup | Used to share objects between apps. |
39+
3540
### Setting
3641

3742
```kotlin
38-
val stringStoredSuccessfully: Boolean = store.set(key = "PASSWORD", value = "546hfbfzzeujfdbfdz")
39-
val intStoredSuccessfully: Boolean = store.set(key = "SECRET", value = 45678765)
40-
val floatStoredSuccessfully: Boolean = store.set(key = "HEIGHT", value = 1.79)
43+
val stringStored: Boolean = store.set(key = "LEET", stringValue = "1337")
44+
val intStored: Boolean = store.set(key = "ANSWER", intValue = 42)
45+
val floatStored: Boolean = store.set(key = "PI", floatValue = 3.14)
4146
```
4247

4348
#### Supported Types
@@ -52,32 +57,32 @@ sourceSets {
5257
### Getting
5358

5459
```kotlin
55-
val stringValue: String? = store.string(forKey = "PASSWORD")
56-
val intValue: Int? = store.int(forKey = "SECRET")
60+
val stringValue: String? = store.string(forKey = "PASSWORD")
61+
val intValue: Int? = store.int(forKey = "SECRET")
5762
```
5863

5964
To check if an object is in the Keychain you can also use:
6065

6166
```kotlin
62-
val existsObject: Boolean = store.existsObject(forKey = "PASSWORD")
67+
val existsObject: Boolean = store.existsObject(forKey = "PASSWORD")
6368
```
6469

6570
### Deleting
6671

6772
#### Single object
6873

6974
```kotlin
70-
val isRemoved: Boolean = store.removeObject(forKey = "PASSWORD")
75+
val isRemoved: Boolean = store.removeObject(forKey = "PASSWORD")
7176
```
7277

7378
#### All objects
7479

7580
##### iOS
7681

77-
⚠️ If the service name and the access group are null it will delete all objects that are in the apps Keychain.
82+
⚠️ If the service name and the access group are not null, it will only delete the objects that match the query.
7883

7984
```kotlin
80-
store.clear()
85+
val isCleared: Boolean = store.clear()
8186
```
8287

8388
## License

iostests/Sources/AppDelegate.swift

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,15 @@
77
//
88

99
import UIKit
10+
import kvault
1011

1112
@main
1213
class AppDelegate: UIResponder, UIApplicationDelegate {
13-
14-
15-
1614
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
17-
// Override point for customization after application launch.
1815
return true
1916
}
2017

21-
// MARK: UISceneSession Lifecycle
22-
2318
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
24-
// Called when a new scene session is being created.
25-
// Use this method to select a configuration to create the new scene with.
2619
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
2720
}
28-
29-
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
30-
// Called when the user discards a scene session.
31-
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
32-
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
33-
}
34-
35-
3621
}
37-
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// DebugViewController.swift
3+
// TestApp
4+
//
5+
// Created by Jan Gaebel on 11.06.21.
6+
//
7+
8+
import UIKit
9+
import kvault
10+
11+
class DebugViewController: UIViewController {
12+
13+
let button = UIButton()
14+
15+
override func viewDidLoad() {
16+
super.viewDidLoad()
17+
18+
title = "test"
19+
view.backgroundColor = .white
20+
view.addSubview(button)
21+
22+
button.translatesAutoresizingMaskIntoConstraints = false
23+
button.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
24+
button.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
25+
button.setTitle("DEBUG", for: .normal)
26+
button.setTitleColor(.red, for: .normal)
27+
28+
button.addTarget(self, action: #selector(debug), for: .touchUpInside)
29+
}
30+
31+
@objc func debug() {
32+
let vault = KVault(serviceName: "DEBUG", accessGroup: nil)
33+
self.performOperations(on: vault)
34+
}
35+
36+
private func performOperations(on vault: KVault) {
37+
vault.set(key: "A", boolValue: true)
38+
vault.set(key: "B", intValue: 1)
39+
vault.set(key: "C", floatValue: 1)
40+
vault.set(key: "D", doubleValue: 1)
41+
vault.set(key: "E", longValue: 1)
42+
vault.set(key: "F", stringValue: "T")
43+
_ = vault.existsObject(forKey: "A")
44+
_ = vault.bool(forKey: "A")
45+
_ = vault.int(forKey: "B")
46+
_ = vault.float(forKey: "C")
47+
_ = vault.double(forKey: "D")
48+
_ = vault.long(forKey: "E")
49+
vault.deleteObject(forKey: "F")
50+
vault.clear()
51+
}
52+
}

iostests/Sources/SceneDelegate.swift

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,13 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
1212

1313
var window: UIWindow?
1414

15-
1615
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
17-
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
18-
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
19-
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
20-
guard let _ = (scene as? UIWindowScene) else { return }
21-
}
22-
23-
func sceneDidDisconnect(_ scene: UIScene) {
24-
// Called as the scene is being released by the system.
25-
// This occurs shortly after the scene enters the background, or when its session is discarded.
26-
// Release any resources associated with this scene that can be re-created the next time the scene connects.
27-
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
28-
}
29-
30-
func sceneDidBecomeActive(_ scene: UIScene) {
31-
// Called when the scene has moved from an inactive state to an active state.
32-
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
33-
}
34-
35-
func sceneWillResignActive(_ scene: UIScene) {
36-
// Called when the scene will move from an active state to an inactive state.
37-
// This may occur due to temporary interruptions (ex. an incoming phone call).
16+
if let windowScene = scene as? UIWindowScene {
17+
let window = UIWindow(windowScene: windowScene)
18+
window.rootViewController = UINavigationController(rootViewController: DebugViewController())
19+
self.window = window
20+
window.makeKeyAndVisible()
21+
}
3822
}
39-
40-
func sceneWillEnterForeground(_ scene: UIScene) {
41-
// Called as the scene transitions from the background to the foreground.
42-
// Use this method to undo the changes made on entering the background.
43-
}
44-
45-
func sceneDidEnterBackground(_ scene: UIScene) {
46-
// Called as the scene transitions from the foreground to the background.
47-
// Use this method to save data, release shared resources, and store enough scene-specific state information
48-
// to restore the scene back to its current state.
49-
}
50-
51-
5223
}
5324

iostests/TestApp.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
3D20E9072659290E0063F320 /* kvault.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D20E9062659290E0063F320 /* kvault.framework */; };
1414
3D20E9082659290E0063F320 /* kvault.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3D20E9062659290E0063F320 /* kvault.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1515
3D20E90B265929B90063F320 /* Keychain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D20E90A265929B90063F320 /* Keychain.swift */; };
16+
3D4BC93E2673E8EF00D12CC3 /* DebugViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D4BC93D2673E8EF00D12CC3 /* DebugViewController.swift */; };
1617
/* End PBXBuildFile section */
1718

1819
/* Begin PBXContainerItemProxy section */
@@ -50,6 +51,7 @@
5051
3D20E9062659290E0063F320 /* kvault.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = kvault.framework; path = ../kvault/build/bin/iosX64/debugFramework/kvault.framework; sourceTree = "<group>"; };
5152
3D20E90A265929B90063F320 /* Keychain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Keychain.swift; sourceTree = "<group>"; };
5253
3D20E90C26592A440063F320 /* TestApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TestApp.entitlements; sourceTree = "<group>"; };
54+
3D4BC93D2673E8EF00D12CC3 /* DebugViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugViewController.swift; sourceTree = "<group>"; };
5355
/* End PBXFileReference section */
5456

5557
/* Begin PBXFrameworksBuildPhase section */
@@ -96,6 +98,7 @@
9698
children = (
9799
3D20E8D5265928990063F320 /* AppDelegate.swift */,
98100
3D20E8D7265928990063F320 /* SceneDelegate.swift */,
101+
3D4BC93D2673E8EF00D12CC3 /* DebugViewController.swift */,
99102
3D20E90A265929B90063F320 /* Keychain.swift */,
100103
3D20E8E32659289C0063F320 /* Info.plist */,
101104
);
@@ -219,6 +222,7 @@
219222
files = (
220223
3D20E90B265929B90063F320 /* Keychain.swift in Sources */,
221224
3D20E8D6265928990063F320 /* AppDelegate.swift in Sources */,
225+
3D4BC93E2673E8EF00D12CC3 /* DebugViewController.swift in Sources */,
222226
3D20E8D8265928990063F320 /* SceneDelegate.swift in Sources */,
223227
);
224228
runOnlyForDeploymentPostprocessing = 0;

iostests/Tests/KeychainTests.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class KeychainTests: XCTestCase {
3434
]
3535

3636
testData.forEach {
37-
sut.set(key: $0.key, value_____: $0.value)
37+
sut.set(key: $0.key, stringValue: $0.value)
3838
XCTAssertNotNil(sut.string(forKey: $0.key), "\($0.key) should not be null")
3939
XCTAssertEqual($0.value, sut.string(forKey: $0.key), "\($0.key) should resolve \($0.value)")
4040
XCTAssertNotEqual(sut.string(forKey: $0.key),
@@ -55,7 +55,7 @@ class KeychainTests: XCTestCase {
5555
]
5656

5757
testData.forEach {
58-
sut.set(key: $0.key, value___: $0.value)
58+
sut.set(key: $0.key, intValue: $0.value)
5959
XCTAssertNotNil(sut.int(forKey: $0.key)?.int32Value, "\($0.key) should not be null")
6060
XCTAssertEqual($0.value, sut.int(forKey: $0.key)?.int32Value, "\($0.key) should resolve \($0.value)")
6161
XCTAssertNotEqual(sut.int(forKey: $0.key)?.int32Value, 1337,
@@ -75,7 +75,7 @@ class KeychainTests: XCTestCase {
7575
]
7676

7777
testData.forEach {
78-
sut.set(key: $0.key, value____: $0.value)
78+
sut.set(key: $0.key, longValue: $0.value)
7979
XCTAssertNotNil(sut.long(forKey: $0.key)?.int64Value, "\($0.key) should not be null")
8080
XCTAssertEqual($0.value, sut.long(forKey: $0.key)?.int64Value, "\($0.key) should resolve \($0.value)")
8181
XCTAssertNotEqual(sut.long(forKey: $0.key)?.int64Value, 1337,
@@ -95,7 +95,7 @@ class KeychainTests: XCTestCase {
9595
]
9696

9797
testData.forEach {
98-
sut.set(key: $0.key, value__: $0.value)
98+
sut.set(key: $0.key, floatValue: $0.value)
9999
XCTAssertNotNil(sut.float(forKey: $0.key)?.floatValue, "\($0.key) should not be null")
100100
XCTAssertEqual($0.value, sut.float(forKey: $0.key)?.floatValue, "\($0.key) should resolve \($0.value)")
101101
XCTAssertNotEqual(sut.float(forKey: $0.key)?.floatValue, 31337.31337,
@@ -115,7 +115,7 @@ class KeychainTests: XCTestCase {
115115
]
116116

117117
testData.forEach {
118-
sut.set(key: $0.key, value_: $0.value)
118+
sut.set(key: $0.key, doubleValue: $0.value)
119119
XCTAssertNotNil(sut.double(forKey: $0.key)?.doubleValue, "\($0.key) should not be null")
120120
XCTAssertEqual($0.value, sut.double(forKey: $0.key)?.doubleValue, "\($0.key) should resolve \($0.value)")
121121
XCTAssertNotEqual(sut.double(forKey: $0.key)?.doubleValue, 31337.31337,
@@ -134,7 +134,7 @@ class KeychainTests: XCTestCase {
134134
]
135135

136136
testData.forEach {
137-
sut.set(key: $0.key, value: $0.value)
137+
sut.set(key: $0.key, boolValue: $0.value)
138138
XCTAssertNotNil(sut.bool(forKey: $0.key)?.boolValue, "\($0.key) should not be null")
139139
XCTAssertEqual($0.value, sut.bool(forKey: $0.key)?.boolValue, "\($0.key) should resolve \($0.value)")
140140
}
@@ -146,23 +146,23 @@ class KeychainTests: XCTestCase {
146146

147147
func testExistsObject() {
148148
XCTAssertFalse(sut.existsObject(forKey: "blank"), "Blank should not exist")
149-
sut.set(key: "blank", value_____: "124")
150-
sut.set(key: "bla", value___: 1)
149+
sut.set(key: "blank", stringValue: "124")
150+
sut.set(key: "bla", intValue: 1)
151151
XCTAssertTrue(sut.existsObject(forKey: "blank"), "Blank should exist")
152152
}
153153

154154
func testDeleteObject() {
155155
XCTAssertFalse(sut.existsObject(forKey: "blank"), "Blank should not exist")
156-
sut.set(key: "blank", value_____: "123")
156+
sut.set(key: "blank", stringValue: "123")
157157
XCTAssertTrue(sut.existsObject(forKey: "blank"), "Blank should exist")
158158
sut.deleteObject(forKey: "blank")
159159
XCTAssertFalse(sut.existsObject(forKey: "blank"), "Blank should not exist anymore")
160160
}
161161

162162
func testOverwrite() {
163-
sut.set(key: "keyX", value_____: "dummyX")
163+
sut.set(key: "keyX", stringValue: "dummyX")
164164
XCTAssertEqual("dummyX", sut.string(forKey: "keyX"))
165-
sut.set(key: "keyX", value_____: "dummyXY")
165+
sut.set(key: "keyX", stringValue: "dummyXY")
166166
XCTAssertEqual("dummyXY", sut.string(forKey: "keyX"))
167167
XCTAssertNotEqual("dummyX", sut.string(forKey: "keyX"))
168168
}
@@ -171,7 +171,7 @@ class KeychainTests: XCTestCase {
171171
let keys = ["key1", "key2", "key3", "key4", "key5"]
172172

173173
keys.forEach {
174-
sut.set(key: $0, value_____: "dummy")
174+
sut.set(key: $0, stringValue: "dummy")
175175
XCTAssertTrue(sut.existsObject(forKey: $0), "\($0) should exist")
176176
}
177177

@@ -189,7 +189,7 @@ class KeychainTests: XCTestCase {
189189

190190
[sut, sut2].forEach { sut in
191191
keys.forEach {
192-
sut.set(key: $0, value_____: "dummy")
192+
sut.set(key: $0, stringValue: "dummy")
193193
XCTAssertTrue(sut.existsObject(forKey: $0), "\($0) should exist")
194194
}
195195
}
@@ -205,7 +205,7 @@ class KeychainTests: XCTestCase {
205205
}
206206

207207
keys.forEach {
208-
sut2.set(key: $0, value_____: "dummy")
208+
sut2.set(key: $0, stringValue: "dummy")
209209
XCTAssertTrue(sut2.existsObject(forKey: $0), "\($0) should exist")
210210
}
211211

@@ -227,7 +227,7 @@ class KeychainTests: XCTestCase {
227227

228228
[sut, sut2].forEach { sut in
229229
keys.forEach {
230-
sut.set(key: $0, value_____: "dummy")
230+
sut.set(key: $0, stringValue: "dummy")
231231
XCTAssertTrue(sut.existsObject(forKey: $0), "\($0) should exist")
232232
}
233233
}

kvault/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ kotlin {
5454
}
5555
}
5656
}
57+
5758
tasks {
5859
val iosX64Test by existing(KotlinNativeSimulatorTest::class) {
5960
filter.excludeTestsMatching("com.liftric.kvault.KVaultTest")

0 commit comments

Comments
 (0)