Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #11 from 4alltecnologia/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
lucaschifino authored Jul 31, 2019
2 parents ab32e55 + 5b606a7 commit 1c93a33
Show file tree
Hide file tree
Showing 94 changed files with 3,489 additions and 403 deletions.
2 changes: 2 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ excluded:
- Carthage
- fastlane
- vendor
nesting:
type_level: 3
force_cast: warning
force_try:
severity: warning
Expand Down
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: objective-c
osx_image: xcode10.2
xcode_project: UtilitiesCore.xcodeproj
xcode_scheme: UtilitiesCore
xcode_destination: platform=iOS Simulator,OS=12.2,name=iPhone X
before_install:
- brew install swiftlint
- swiftlint
2 changes: 1 addition & 1 deletion 4allUtilitiesCore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "4allUtilitiesCore"
s.version = "0.0.1"
s.version = "0.1.0"
s.summary = "A utilities core library."

# This description is used to generate tags and improve search results.
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# ios-utilities
# ios-utilities [![swift version](https://img.shields.io/badge/swift-5-orange.svg)](https://swift.org) [![xcode version](https://img.shields.io/badge/Xcode-10.2-blue.svg)](https://developer.apple.com/xcode) [![carthage](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)

We are happy to announce the iOS Utilities Core, this framework comes to encapsulate all common code among the projects at 4All (https://4all.com)

#[Documentation](https://github.com/4alltecnologia/ios-utilities/docs/index.html)
#[Documentation](https://4alltecnologia.github.io/ios-utilities/)

# Rules for contribution
- All commits need to be 100% tested.
- All comments and code must be in english.
- Always create documentation in every function. (iOS default documentation)
- All PRs need to have "develop" as target branch.
- For a PR to be approved, it needs to have at least 2 developers approval and every discussion needs to be solved.
- If you have a suggestion but no time to implement, please open an issue. Feel free to submit the solution to any open issue, always remember to assign yourself to the issue.
42 changes: 38 additions & 4 deletions UtilitiesCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
0259946A22C531400017850B /* CpfValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0259946922C531400017850B /* CpfValidatorTests.swift */; };
0259946C22C53A0A0017850B /* CnpjValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0259946B22C53A0A0017850B /* CnpjValidator.swift */; };
0259946E22C53B2B0017850B /* CnpjValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0259946D22C53B2B0017850B /* CnpjValidatorTests.swift */; };
C90551D122B27F4900FC600A /* DecodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90551D022B27F4900FC600A /* DecodableTests.swift */; };
C92250A3227B4D8400ABFB38 /* UtilitiesCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9225099227B4D8400ABFB38 /* UtilitiesCore.framework */; };
C92250AA227B4D8400ABFB38 /* UtilitiesCore.h in Headers */ = {isa = PBXBuildFile; fileRef = C922509C227B4D8400ABFB38 /* UtilitiesCore.h */; settings = {ATTRIBUTES = (Public, ); }; };
C92250C0227B527800ABFB38 /* Decimal+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C92250B6227B527700ABFB38 /* Decimal+Extension.swift */; };
Expand Down Expand Up @@ -39,6 +40,8 @@
C9835D00228319AC00DB672B /* CustomValidatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9835CFF228319AC00DB672B /* CustomValidatorTests.swift */; };
C9835D02228320FF00DB672B /* UITextField+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9835D01228320FF00DB672B /* UITextField+Extension.swift */; };
C9835D0422833FBD00DB672B /* UITextFieldTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9835D0322833FBD00DB672B /* UITextFieldTests.swift */; };
C99B09B522B27C5E00AADF3B /* Encodable+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99B09B422B27C5E00AADF3B /* Encodable+Extensions.swift */; };
C99B09B722B27CC800AADF3B /* Decode+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99B09B622B27CC800AADF3B /* Decode+Extension.swift */; };
C9ED4A5B229D91F100939BFB /* Encodable+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9ED4A5A229D91F100939BFB /* Encodable+Extension.swift */; };
C9ED4A5D229D920800939BFB /* EncodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9ED4A5C229D920800939BFB /* EncodableTests.swift */; };
/* End PBXBuildFile section */
Expand All @@ -58,6 +61,7 @@
0259946922C531400017850B /* CpfValidatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CpfValidatorTests.swift; sourceTree = "<group>"; };
0259946B22C53A0A0017850B /* CnpjValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CnpjValidator.swift; sourceTree = "<group>"; };
0259946D22C53B2B0017850B /* CnpjValidatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CnpjValidatorTests.swift; sourceTree = "<group>"; };
C90551D022B27F4900FC600A /* DecodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodableTests.swift; sourceTree = "<group>"; };
C9225099227B4D8400ABFB38 /* UtilitiesCore.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = UtilitiesCore.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C922509C227B4D8400ABFB38 /* UtilitiesCore.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UtilitiesCore.h; sourceTree = "<group>"; };
C922509D227B4D8400ABFB38 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -89,6 +93,8 @@
C9835CFF228319AC00DB672B /* CustomValidatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomValidatorTests.swift; sourceTree = "<group>"; };
C9835D01228320FF00DB672B /* UITextField+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextField+Extension.swift"; sourceTree = "<group>"; };
C9835D0322833FBD00DB672B /* UITextFieldTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITextFieldTests.swift; sourceTree = "<group>"; };
C99B09B422B27C5E00AADF3B /* Encodable+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Encodable+Extensions.swift"; sourceTree = "<group>"; };
C99B09B622B27CC800AADF3B /* Decode+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Decode+Extension.swift"; sourceTree = "<group>"; };
C9ED4A5A229D91F100939BFB /* Encodable+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Encodable+Extension.swift"; sourceTree = "<group>"; };
C9ED4A5C229D920800939BFB /* EncodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncodableTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -160,6 +166,8 @@
C92250B9227B527700ABFB38 /* DateFormatter+Extension.swift */,
C92250BA227B527700ABFB38 /* Colletion+Extension.swift */,
C9835D01228320FF00DB672B /* UITextField+Extension.swift */,
C99B09B422B27C5E00AADF3B /* Encodable+Extensions.swift */,
C99B09B622B27CC800AADF3B /* Decode+Extension.swift */,
C9ED4A5A229D91F100939BFB /* Encodable+Extension.swift */,
);
path = Extensions;
Expand All @@ -173,6 +181,7 @@
C92250CD227B62C700ABFB38 /* NumberFormatterTests.swift */,
C92250CF227B683500ABFB38 /* StringTests.swift */,
C9835D0322833FBD00DB672B /* UITextFieldTests.swift */,
C90551D022B27F4900FC600A /* DecodableTests.swift */,
C9ED4A5C229D920800939BFB /* EncodableTests.swift */,
);
path = Extensions;
Expand Down Expand Up @@ -233,6 +242,7 @@
C9225095227B4D8400ABFB38 /* Sources */,
C9225096227B4D8400ABFB38 /* Frameworks */,
C9225097227B4D8400ABFB38 /* Resources */,
C9B57C8E22C557200088F299 /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -315,6 +325,27 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
C9B57C8E22C557200088F299 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = SwiftLint;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
C9225095227B4D8400ABFB38 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand All @@ -327,6 +358,7 @@
C92250C0227B527800ABFB38 /* Decimal+Extension.swift in Sources */,
C9835CD82281B8A800DB672B /* Validator.swift in Sources */,
C9835CEF2282042B00DB672B /* AlphabetValidator.swift in Sources */,
C99B09B522B27C5E00AADF3B /* Encodable+Extensions.swift in Sources */,
0259946C22C53A0A0017850B /* CnpjValidator.swift in Sources */,
C92250C2227B527800ABFB38 /* String+Extension.swift in Sources */,
C9ED4A5B229D91F100939BFB /* Encodable+Extension.swift in Sources */,
Expand All @@ -335,6 +367,7 @@
C92250C4227B527800ABFB38 /* Colletion+Extension.swift in Sources */,
0259946822C52F7F0017850B /* CpfValidator.swift in Sources */,
C9835CEE2282030600DB672B /* FutureDateValidator.swift in Sources */,
C99B09B722B27CC800AADF3B /* Decode+Extension.swift in Sources */,
C92250C1227B527800ABFB38 /* NumberFormatter+Extension.swift in Sources */,
C9835CF12282065B00DB672B /* CustomValidator.swift in Sources */,
);
Expand All @@ -357,6 +390,7 @@
C9ED4A5D229D920800939BFB /* EncodableTests.swift in Sources */,
C9835CF8228220B300DB672B /* ValidAgeValidatorTests.swift in Sources */,
C92250CE227B62C700ABFB38 /* NumberFormatterTests.swift in Sources */,
C90551D122B27F4900FC600A /* DecodableTests.swift in Sources */,
C92250CC227B5FCB00ABFB38 /* DateFormatterTests.swift in Sources */,
C92250CA227B57FB00ABFB38 /* CollectionTests.swift in Sources */,
);
Expand Down Expand Up @@ -425,7 +459,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -483,7 +517,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -508,7 +542,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = UtilitiesCore/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -536,7 +570,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = UtilitiesCore/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
26 changes: 24 additions & 2 deletions UtilitiesCore/Extensions/DateFormatter+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,31 @@ import Foundation
public extension DateFormatter {

/// Default brazilian date formatt dd/MM/yyyy
static let brazillianDateFormatWithoutTime: DateFormatter = {
static var brazillianDateFormatWithoutTime: DateFormatter {
let formatter = DateFormatter()
formatter.dateFormat = "dd/MM/yyyy"
return formatter
}()
}
}

extension ISO8601DateFormatter {
//swiftlint:disable force_unwrapping
convenience init(_ formatOptions: Options, timeZone: TimeZone = TimeZone(secondsFromGMT: 0)!) {
self.init()
self.formatOptions = formatOptions
self.timeZone = timeZone
}
}

extension Formatter {
static var iso8601: ISO8601DateFormatter {
let formatter = ISO8601DateFormatter()
if #available(iOS 11.0, *) {
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
} else {
formatter.formatOptions = [.withInternetDateTime]
}
return formatter
}
static let iso8601noFS = ISO8601DateFormatter()
}
20 changes: 20 additions & 0 deletions UtilitiesCore/Extensions/Decode+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Decode+Extension.swift
// UtilitiesCore
//
// Created by Felipe Dias Pereira on 13/06/19.
// Copyright © 2019 4all. All rights reserved.
//

import Foundation

extension JSONDecoder.DateDecodingStrategy {
static let customISO8601 = custom {
let container = try $0.singleValueContainer()
let string = try container.decode(String.self)
if let date = Formatter.iso8601.date(from: string) ?? Formatter.iso8601noFS.date(from: string) {
return date
}
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Invalid date: \(string)")
}
}
1 change: 0 additions & 1 deletion UtilitiesCore/Extensions/Encodable+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ extension Encodable {
return dictionary[key]
}


/// Create a dictionary from Encodable object, uses jsonEncodar and JsonSerialization to do so
var dictionary: [String: Any] {
return (try? JSONSerialization.jsonObject(with: JSONEncoder().encode(self))) as? [String: Any] ?? [:]
Expand Down
16 changes: 16 additions & 0 deletions UtilitiesCore/Extensions/Encodable+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Encodable+Extensions.swift
// UtilitiesCore
//
// Created by Felipe Dias Pereira on 13/06/19.
// Copyright © 2019 4all. All rights reserved.
//

import Foundation

extension JSONEncoder.DateEncodingStrategy {
static let customISO8601 = custom {
var container = $1.singleValueContainer()
try container.encode(Formatter.iso8601.string(from: $0))
}
}
6 changes: 3 additions & 3 deletions UtilitiesCore/Extensions/NumberFormatter+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import Foundation

public extension NumberFormatter {

/// Returns a currency formatter with brazillian settings
static let brazilianCurrencyFormatter: NumberFormatter = {
/// Use this variable to get double value from decimal
static var brazilianCurrencyFormatter: NumberFormatter {
let formatter = NumberFormatter()
formatter.numberStyle = .currencyAccounting
formatter.locale = Locale(identifier: "pt_BR")
formatter.maximumFractionDigits = 2
formatter.minimumFractionDigits = 2
return formatter
}()
}
}
11 changes: 5 additions & 6 deletions UtilitiesCore/Extensions/String+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ public extension String {
let hasLetters = rangeOfCharacter(from: .letters, options: .numeric, range: nil) != nil
let hasNumbers = rangeOfCharacter(from: .decimalDigits, options: .literal, range: nil) != nil
let comps = components(separatedBy: .alphanumerics)
return comps.joined(separator: "").count == 0 && hasLetters && hasNumbers
return comps.joined(separator: "").isEmpty && hasLetters && hasNumbers
}
}

public extension String {
/// Dictionary from string JSON format
var toDictionary: [String: Any]? {
var toDictionary: [String: Any] {
if let data = data(using: .utf8) {
do {
return try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
return try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] ?? [:]
} catch {
return nil
return [:]
}
}
return nil
return [:]
}
}

Expand All @@ -115,7 +115,6 @@ public extension String {
}
}


/// Create a substring based on the range passed
///
/// - Parameter range: range to create the substring
Expand Down
2 changes: 1 addition & 1 deletion UtilitiesCore/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.0.1</string>
<string>0.1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
Expand Down
4 changes: 2 additions & 2 deletions UtilitiesCore/Validators/CnpjValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension CnpjValidator: ValidatorConvertible {
}

private func validateNumbersCNPJ(cnpj: String) -> Bool {
let numbers = cnpj.compactMap({ Int(String($0)) })
let numbers = cnpj.compactMap { Int(String($0)) }

guard numbers.count == 14 && Set(numbers).count != 1 else { return false }

Expand All @@ -51,7 +51,7 @@ extension CnpjValidator: ValidatorConvertible {

if number == 9 { number = 1 }

} % 11
} % 11

return digit > 9 ? 0 : digit
}
Expand Down
2 changes: 1 addition & 1 deletion UtilitiesCore/Validators/CpfValidator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension CpfValidator: ValidatorConvertible {
}

private func validateNumbersCPF(cpf: String) -> Bool {
let numbers = cpf.compactMap( { Int(String($0)) } )
let numbers = cpf.compactMap { Int(String($0)) }

guard numbers.count == 11 && Set(numbers).count != 1 else { return false }

Expand Down
15 changes: 15 additions & 0 deletions UtilitiesCoreTests/Extensions/DateFormatterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,19 @@ class DateFormatterTests: XCTestCase {
XCTAssertEqual(dateComponents.month, 09)
XCTAssertEqual(dateComponents.year, 1990)
}

func testIso8601CustomFormat() {
let dateString = "2019-03-12T19:18:11.000Z"
let date = Formatter.iso8601.date(from: dateString)

//swiftlint:disable force_unwrapping
let dateComponents = Calendar.current.dateComponents(in: TimeZone(abbreviation: "UTC")!, from: date!)

XCTAssertEqual(dateComponents.day, 12)
XCTAssertEqual(dateComponents.month, 03)
XCTAssertEqual(dateComponents.year, 2019)
XCTAssertEqual(dateComponents.hour, 19)
XCTAssertEqual(dateComponents.minute, 18)
XCTAssertEqual(dateComponents.second, 11)
}
}
Loading

0 comments on commit 1c93a33

Please sign in to comment.