Skip to content

Commit

Permalink
Merge pull request #16 from AckeeCZ/th/newFeatures
Browse files Browse the repository at this point in the history
Th/new features
  • Loading branch information
janmisar authored Aug 14, 2017
2 parents 143c3c3 + eb4a7d9 commit 034657d
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ACKategories.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'ACKategories'
s.version = '4.1.0'
s.version = '4.2.0'
s.summary = 'A bunch of useful tools, cocoa subclasses and extensions'

# This description is used to generate tags and improve search results.
Expand Down
83 changes: 83 additions & 0 deletions ACKategories/Classes/FoundationExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// FoundationExtensions.swift
// Pods
//
// Created by Tomas Holka on 29/06/2017.
//
//

import Foundation


public protocol OptionalProtocol {
associatedtype WrappedValue
var optional: WrappedValue? {get}
}

extension Optional: OptionalProtocol {
public typealias WrappedValue = Wrapped
public var optional: WrappedValue? { return self }
}


extension Dictionary where Value: OptionalProtocol {


// Removes nils from dictionary
public var nilsRemoved: [Key: Value.WrappedValue] {
return self.reduce([:]) { acc, element -> [Key: Value.WrappedValue] in

if let value = element.value.optional {
var result = acc
result[element.key] = value
return result
} else {
return acc
}
}
}



/**
Simulation of classic valueForKeyPath method.

- Parameter keyPath: Dot separated key path
*/
public func value<T>(for keyPath: String) -> T? {
let components = keyPath.components(separatedBy: ".")

var result: Any? = self
components.forEach { key in
guard let key = key as? Key else {
return
}
result = (result as? Dictionary<Key, Value>)?[key]
}
return result as? T
}


}



extension Optional where Wrapped == String {
public var isEmpty: Bool {
switch self {
case .none:
return true
case .some(let value):
return value.isEmpty
}
}
}


extension NumberFormatter {

public func string(from number: Int) -> String? {
return self.string(from: NSNumber(value: number))
}

}
9 changes: 9 additions & 0 deletions ACKategories/Classes/String+Extra.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@ extension String {
guard length > 0 else { return nil }
return substring(to: characters.index(after: startIndex))
}

/// Normalizes string - removes interpuction etc.
public func normalizedValue() -> String {
let mutableString = NSMutableString(string: self) as CFMutableString
CFStringTransform(mutableString, nil, kCFStringTransformToLatin, Bool(0))
CFStringTransform(mutableString, nil, kCFStringTransformStripCombiningMarks, Bool(0))
CFStringLowercase(mutableString, Locale.current as CFLocale!)
return mutableString as String
}
}
4 changes: 4 additions & 0 deletions Example/ACKategories.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
1776132C1D7782EA00E56066 /* ColorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1776132B1D7782EA00E56066 /* ColorTests.swift */; };
17A99DD41D775EDE00948965 /* MemoryLeakConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17A99DD31D775EDE00948965 /* MemoryLeakConfiguration.swift */; };
18D2D62FD0C175CE22B7169C /* Pods_ACKategories_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B4AC20B3D608CCB8989AEE1 /* Pods_ACKategories_Example.framework */; };
1CF5E2441F05465A0091E22B /* FoundationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CF5E2431F05465A0091E22B /* FoundationTests.swift */; };
3D3D271BCA9967761726E10A /* Pods_ACKategories_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 624F81B9D65FD4A16E0EABE3 /* Pods_ACKategories_Tests.framework */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
Expand All @@ -34,6 +35,7 @@
031F117190A5BB287215D082 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
1776132B1D7782EA00E56066 /* ColorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorTests.swift; sourceTree = "<group>"; };
17A99DD31D775EDE00948965 /* MemoryLeakConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MemoryLeakConfiguration.swift; sourceTree = "<group>"; };
1CF5E2431F05465A0091E22B /* FoundationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationTests.swift; sourceTree = "<group>"; };
2F685728DFC343C6C35320D4 /* Pods-ACKategories_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ACKategories_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ACKategories_Tests/Pods-ACKategories_Tests.debug.xcconfig"; sourceTree = "<group>"; };
3DA1857613DF31894F224EF6 /* Pods-ACKategories_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ACKategories_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ACKategories_Tests/Pods-ACKategories_Tests.release.xcconfig"; sourceTree = "<group>"; };
4631ACD545F32E3CBC276342 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -133,6 +135,7 @@
607FACEB1AFB9204008FA782 /* ControlBlocksTests.swift */,
1776132B1D7782EA00E56066 /* ColorTests.swift */,
69CB1F181D7EDD5B0036F0C9 /* StringTests.swift */,
1CF5E2431F05465A0091E22B /* FoundationTests.swift */,
607FACE91AFB9204008FA782 /* Supporting Files */,
);
path = Tests;
Expand Down Expand Up @@ -391,6 +394,7 @@
607FACEC1AFB9204008FA782 /* ControlBlocksTests.swift in Sources */,
69CB1F1A1D7EDE370036F0C9 /* StringTests.swift in Sources */,
1776132C1D7782EA00E56066 /* ColorTests.swift in Sources */,
1CF5E2441F05465A0091E22B /* FoundationTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
14 changes: 9 additions & 5 deletions Example/ACKategories/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -14,9 +18,9 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
Expand Down
4 changes: 4 additions & 0 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions Example/Tests/FoundationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// FoundationTests.swift
// ACKategories
//
// Created by Tomas Holka on 29/06/2017.
// Copyright © 2017 CocoaPods. All rights reserved.
//

import Foundation
import Quick
import Nimble
import ACKategories

class FoundationSpec: QuickSpec {
override func spec() {
describe("Dictionary") {

it("counts correctly") {
let dict: [String:Any?] = ["key":1, "key2":"value2", "key3":nil]
let dictWithoutNils = dict.nilsRemoved

expect(dict.count) == 3
expect(dictWithoutNils.count) == 2
}


it("gets correct value") {
let dict: [String:Any?] = ["key":1, "key2":["key3":3.17]]
let value1: Int = dict.value(for: "key")!
let value2: Double = dict.value(for: "key2.key3")!

expect(value1) == 1
expect(value2) == 3.17
}
}


describe("Optional") {

it("checks if string is empty") {

let string1: String? = "test"
let string2: String? = nil
let string3: String? = ""

expect(string1.isEmpty) == false
expect(string2.isEmpty) == true
expect(string3.isEmpty) == true
}
}


describe("NumberFormatter") {

it("converts int to string") {
let numberFormatter = NumberFormatter()
let integer = 10
let numberString = numberFormatter.string(from: integer)

expect(numberString) == "10"
}
}
}
}
7 changes: 7 additions & 0 deletions Example/Tests/StringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class StringSpec: QuickSpec {

expect(string.trimmed()) == "String\nString"
}


it("normalizes") {
let string = "řžýřšč"

expect(string.normalizedValue()) == "rzyrsc"
}
}
}
}

0 comments on commit 034657d

Please sign in to comment.