Skip to content

Commit 6be8b50

Browse files
committed
updated CodableUserDefaults.podspec
1 parent 6483927 commit 6be8b50

File tree

7 files changed

+107
-178
lines changed

7 files changed

+107
-178
lines changed

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: objective-c
2+
3+
osx_image: xcode10.1
4+
env:
5+
matrix:
6+
- TEST_SDK=iphonesimulator12.1 OS=12.1 NAME='iPhone XR'
7+
- TEST_SDK=iphonesimulator12.1 OS=12.1 NAME='iPhone 7'
8+
9+
script:
10+
- set -o pipefail && xcodebuild test -enableCodeCoverage YES -project CodableUserDefaults.xcodeproj -scheme CodableUserDefaults -sdk $TEST_SDK -destination "platform=iOS Simulator,OS=$OS,name=$NAME" ONLY_ACTIVE_ARCH=YES

CodableUserDefaults.podspec

Lines changed: 7 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,17 @@
1-
#
2-
# Be sure to run `pod spec lint CodableUserDefaults.podspec' to ensure this is a
3-
# valid spec and to remove all comments including this before submitting the spec.
4-
#
5-
# To learn more about Podspec attributes see https://guides.cocoapods.org/syntax/podspec.html
6-
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
7-
#
8-
91
Pod::Spec.new do |spec|
102
spec.name = "CodableUserDefaults"
113
spec.version = "0.0.1"
124
spec.summary = "A simple implementation of Codables with UserDefaults."
135
spec.description = "CodableUserDefaults gives you the power to implement UserDefaults with codable seamlessly, look at it as icing on the cake."
14-
15-
spec.homepage = "http://EXAMPLE/CodableUserDefaults"
16-
# spec.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
17-
18-
19-
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
20-
#
21-
# Licensing your code is important. See https://choosealicense.com for more info.
22-
# CocoaPods will detect a license file if there is a named LICENSE*
23-
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
24-
#
25-
26-
spec.license = "MIT (example)"
27-
# spec.license = { :type => "MIT", :file => "FILE_LICENSE" }
28-
29-
30-
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
31-
#
32-
# Specify the authors of the library, with email addresses. Email addresses
33-
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
34-
# accepts just a name if you'd rather not provide an email address.
35-
#
36-
# Specify a social_media_url where others can refer to, for example a twitter
37-
# profile URL.
38-
#
39-
6+
spec.homepage = "http://github.com/AdieOlami/CodableUserDefaults"
7+
spec.license = { :type => "MIT", :file => "LICENSE" }
408
spec.author = { "Adie Olalekan" => "ugbeadie@gmail.com" }
41-
# Or just: spec.author = "Adie Olalekan"
42-
# spec.authors = { "Adie Olalekan" => "ugbeadie@gmail.com" }
43-
# spec.social_media_url = "https://twitter.com/Adie Olalekan"
44-
45-
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
46-
#
47-
# If this Pod runs only on iOS or OS X, then specify the platform and
48-
# the deployment target. You can optionally include the target after the platform.
49-
#
50-
51-
# spec.platform = :ios
52-
# spec.platform = :ios, "5.0"
53-
54-
# When using multiple platforms
55-
# spec.ios.deployment_target = "5.0"
56-
# spec.osx.deployment_target = "10.7"
57-
# spec.watchos.deployment_target = "2.0"
58-
# spec.tvos.deployment_target = "9.0"
59-
60-
61-
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
62-
#
63-
# Specify the location from where the source should be retrieved.
64-
# Supports git, hg, bzr, svn and HTTP.
65-
#
66-
67-
spec.source = { :git => "http://EXAMPLE/CodableUserDefaults.git", :tag => "#{spec.version}" }
68-
69-
70-
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
71-
#
72-
# CocoaPods is smart about how it includes source code. For source files
73-
# giving a folder will include any swift, h, m, mm, c & cpp files.
74-
# For header files it will include any header in the folder.
75-
# Not including the public_header_files will make all headers public.
76-
#
77-
78-
spec.source_files = "Classes", "Classes/**/*.{h,m}"
79-
spec.exclude_files = "Classes/Exclude"
80-
81-
# spec.public_header_files = "Classes/**/*.h"
82-
83-
84-
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
85-
#
86-
# A list of resources included with the Pod. These are copied into the
87-
# target bundle with a build phase script. Anything else will be cleaned.
88-
# You can preserve files from being cleaned, please don't preserve
89-
# non-essential files like tests, examples and documentation.
90-
#
91-
92-
# spec.resource = "icon.png"
93-
# spec.resources = "Resources/*.png"
94-
95-
# spec.preserve_paths = "FilesToSave", "MoreFilesToSave"
96-
97-
98-
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
99-
#
100-
# Link your library with frameworks, or libraries. Libraries do not include
101-
# the lib prefix of their name.
102-
#
103-
104-
# spec.framework = "SomeFramework"
105-
# spec.frameworks = "SomeFramework", "AnotherFramework"
106-
107-
# spec.library = "iconv"
108-
# spec.libraries = "iconv", "xml2"
109-
110-
111-
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
112-
#
113-
# If your library depends on compiler flags you can set them in the xcconfig hash
114-
# where they will only apply to your library. If you depend on other Podspecs
115-
# you can include multiple dependencies to ensure it works.
9+
spec.social_media_url = "https://twitter.com/AdieOlami"
11610

117-
# spec.requires_arc = true
11+
spec.source = { :git => "https://github.com/AdieOlami/CodableUserDefaults.git", :tag => "#{spec.version}" }
11812

119-
# spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
120-
# spec.dependency "JSONKit", "~> 1.4"
13+
spec.source_files = "CodableUserDefaults/**/*.{swift}"
14+
spec.swift_versions = '5.0'
15+
spec.ios.deployment_target = "9.0"
12116

12217
end
6.71 KB
Binary file not shown.

CodableUserDefaults/Source/CodableUserDefaults.swift

Lines changed: 64 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,75 +8,78 @@
88

99
import Foundation
1010

11-
var defaults = UserDefaults.standard
12-
13-
public func saveArray<T: Equatable>(type data: T, key: String) where T: Codable {
14-
var saveArraData: [T] = getAllData(key: key)
15-
if saveArraData.contains(data) {
16-
saveArraData.remove(at: saveArraData.firstIndex(of: data)!)
17-
} else {
18-
saveArraData.append(data)
19-
}
20-
let encoder = JSONEncoder()
21-
do {
11+
public final class CodableUserDefaults {
12+
var defaults = UserDefaults.standard
13+
14+
public func saveArray<T: Equatable>(type data: T, key: String) where T: Codable {
15+
var saveArraData: [T] = getAllData(key: key)
16+
if saveArraData.contains(data) {
17+
saveArraData.remove(at: saveArraData.firstIndex(of: data)!)
18+
} else {
19+
saveArraData.append(data)
20+
}
21+
let encoder = JSONEncoder()
22+
do {
2223
// encoder.keyEncodingStrategy = .convertToSnakeCase
23-
let encoded = try encoder.encode(saveArraData)
24-
defaults.set(encoded, forKey: key)
25-
defaults.synchronize()
26-
} catch let error {
27-
fatalError("fatal encoded \(error))")
24+
let encoded = try encoder.encode(saveArraData)
25+
defaults.set(encoded, forKey: key)
26+
defaults.synchronize()
27+
} catch let error {
28+
fatalError("fatal encoded \(error))")
29+
}
30+
2831
}
2932

30-
}
31-
32-
public func save<T: Equatable>(type data: T, key: String) where T: Codable {
33-
var saveArraData: [T] = getAllData(key: key)
34-
if saveArraData.contains(data) {
35-
saveArraData.remove(at: saveArraData.firstIndex(of: data)!)
36-
} else {
37-
saveArraData.append(data)
38-
}
39-
let encoder = JSONEncoder()
40-
do {
33+
public func save<T: Equatable>(type data: T, key: String) where T: Codable {
34+
var saveArraData: [T] = getAllData(key: key)
35+
if saveArraData.contains(data) {
36+
saveArraData.remove(at: saveArraData.firstIndex(of: data)!)
37+
} else {
38+
saveArraData.append(data)
39+
}
40+
let encoder = JSONEncoder()
41+
do {
4142
// encoder.keyEncodingStrategy = .convertToSnakeCase
42-
let encoded = try encoder.encode(saveArraData)
43-
defaults.set(encoded, forKey: key)
44-
defaults.synchronize()
45-
} catch let error {
46-
fatalError("fatal encoded \(error)) boom")
43+
let encoded = try encoder.encode(saveArraData)
44+
defaults.set(encoded, forKey: key)
45+
defaults.synchronize()
46+
} catch let error {
47+
fatalError("fatal encoded \(error)) boom")
48+
}
49+
4750
}
4851

49-
}
50-
51-
public func edit<T>(dataPass: T, index: Int, key: String) where T: Codable {
52-
var array: [T] = getAllData(key: key)
53-
array[index] = dataPass
54-
defaults.setValue(array, forKey: key)
55-
}
56-
57-
public func clear(key: String) {
58-
defaults.removeObject(forKey: key)
59-
}
60-
61-
public func getAllData<T>(key: String) -> [T] where T: Codable {
62-
if defaults.value(forKey: key) == nil {
63-
let array = [T]()
64-
return array
52+
public func edit<T>(dataPass: T, index: Int, key: String) where T: Codable {
53+
var array: [T] = getAllData(key: key)
54+
array[index] = dataPass
55+
defaults.setValue(array, forKey: key)
6556
}
66-
if let objects = defaults.data(forKey: key) {
67-
68-
let decoder = JSONDecoder()
69-
do {
57+
58+
public func clear(key: String) {
59+
defaults.removeObject(forKey: key)
60+
}
61+
62+
public func getAllData<T>(key: String) -> [T] where T: Codable {
63+
if defaults.value(forKey: key) == nil {
64+
let array = [T]()
65+
return array
66+
}
67+
if let objects = defaults.data(forKey: key) {
68+
69+
let decoder = JSONDecoder()
70+
do {
7071
// decoder.keyDecodingStrategy = .convertFromSnakeCase
71-
let objectsDecoded = try decoder.decode([T].self, from: objects)
72-
print("(BOUNCEE CC) objects \(objectsDecoded)) boom")
73-
return objectsDecoded
74-
} catch let error {
75-
fatalError("(BOUNCEE CC) fatal \(error)) boom")
72+
let objectsDecoded = try decoder.decode([T].self, from: objects)
73+
print("(BOUNCEE CC) objects \(objectsDecoded)) boom")
74+
return objectsDecoded
75+
} catch let error {
76+
fatalError("(BOUNCEE CC) fatal \(error)) boom")
77+
}
78+
79+
} else {
80+
let array = [T]()
81+
return array
7682
}
77-
78-
} else {
79-
let array = [T]()
80-
return array
8183
}
84+
8285
}

CodableUserDefaultsTests/CodableUserDefaultsTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ import XCTest
1010
@testable import CodableUserDefaults
1111

1212
class CodableUserDefaultsTests: XCTestCase {
13+
14+
var cUD: CodableUserDefaults!
1315

1416
override func setUp() {
15-
// Put setup code here. This method is called before the invocation of each test method in the class.
17+
cUD = CodableUserDefaults()
1618
}
1719

1820
override func tearDown() {
19-
// Put teardown code here. This method is called after the invocation of each test method in the class.
2021
}
2122

22-
func testExample() {
23-
// This is an example of a functional test case.
24-
// Use XCTAssert and related functions to verify your tests produce the correct results.
23+
func testSave() {
24+
2525
}
2626

2727
func testPerformanceExample() {

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Adie Olalekan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

LICENSE.md

Whitespace-only changes.

0 commit comments

Comments
 (0)