Skip to content

Commit

Permalink
Merge branch 'deploy/1.4.0' into productive
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Jan 11, 2017
2 parents 11fa6f5 + c1a1417 commit 1388035
Show file tree
Hide file tree
Showing 26 changed files with 194 additions and 280 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Expand Up @@ -7,6 +7,7 @@ disabled_rules:

included:
- Sources
- Tests

excluded:
- Carthage
Expand Down
4 changes: 2 additions & 2 deletions HandySwift.podspec
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "HandySwift"
s.version = "1.3.1"
s.version = "1.4.0"
s.summary = "Handy Swift features that didn't make it into the Swift standard library"

s.description = <<-DESC
Expand All @@ -20,7 +20,7 @@ Pod::Spec.new do |s|
s.osx.deployment_target = "10.10"
s.tvos.deployment_target = "9.0"

s.source = { :git => "https://github.com/Flinesoft/HandySwift.git", :tag => "1.3.1" }
s.source = { :git => "https://github.com/Flinesoft/HandySwift.git", :tag => "1.4.0" }
s.source_files = "Sources", "Sources/**/*.swift"
s.framework = "Foundation"
s.osx.framework = "AppKit"
Expand Down
30 changes: 20 additions & 10 deletions HandySwift.xcodeproj/project.pbxproj
Expand Up @@ -141,6 +141,7 @@
82F967F31C67A65E0003F12A /* .swiftlint.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = "<group>"; };
A16B85EB1D8EA9A200B39055 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
A19DD6921DE2B70F00C66584 /* HandySwift.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = HandySwift.podspec; sourceTree = "<group>"; };
A1F5AEEB1E05702E003D6949 /* .swift-version */ = {isa = PBXFileReference; lastKnownFileType = text; path = ".swift-version"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -195,10 +196,7 @@
823B2B271C24AAB6007B3CDD = {
isa = PBXGroup;
children = (
A16B85EB1D8EA9A200B39055 /* README.md */,
82F967F31C67A65E0003F12A /* .swiftlint.yml */,
82F22E551C26434900E784A2 /* Package.swift */,
A19DD6921DE2B70F00C66584 /* HandySwift.podspec */,
A1F5AEEA1E05700F003D6949 /* Root Files */,
825EFDE11C3333CE00558497 /* Sources */,
825EFDE21C3333D200558497 /* Tests */,
823B2B321C24AAB6007B3CDD /* Products */,
Expand Down Expand Up @@ -305,6 +303,18 @@
path = "Supporting Files";
sourceTree = "<group>";
};
A1F5AEEA1E05700F003D6949 /* Root Files */ = {
isa = PBXGroup;
children = (
A16B85EB1D8EA9A200B39055 /* README.md */,
82F967F31C67A65E0003F12A /* .swiftlint.yml */,
82F22E551C26434900E784A2 /* Package.swift */,
A19DD6921DE2B70F00C66584 /* HandySwift.podspec */,
A1F5AEEB1E05702E003D6949 /* .swift-version */,
);
name = "Root Files";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -458,27 +468,27 @@
TargetAttributes = {
823B2B301C24AAB6007B3CDD = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
LastSwiftMigration = 0820;
};
823B2B3A1C24AAB7007B3CDD = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
LastSwiftMigration = 0820;
};
825EFDC91C3333B000558497 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
LastSwiftMigration = 0820;
};
825EFDD21C3333B000558497 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
LastSwiftMigration = 0820;
};
825EFDE81C33351200558497 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
LastSwiftMigration = 0820;
};
825EFDF11C33351300558497 = {
CreatedOnToolsVersion = 7.2;
LastSwiftMigration = 0800;
LastSwiftMigration = 0820;
};
};
};
Expand Down
16 changes: 13 additions & 3 deletions README.md
Expand Up @@ -128,7 +128,7 @@ Int(randomBelow: 1_000_000) // => 208041
Repeat some code block a given number of times.

``` Swift
3.times{ array.append("Hello World!") }
3.times { array.append("Hello World!") }
// => ["Hello World!", "Hello World!", "Hello World!"]

5.times {
Expand Down Expand Up @@ -191,6 +191,16 @@ Returns an array with `size` random elements or nil if array empty.
([] as [Int]).sample(size: 3) // => nil
```


#### .combinations(with:)

Combines each element with each element of a given other array.

``` Swift
[1, 2, 3].combinations(with: ["A", "B"])
// => [(1, "A"), (1, "B"), (2, "A"), (2, "B"), (3, "A"), (3, "B")]
```

### DictionaryExtension
#### init?(keys:values:)

Expand Down Expand Up @@ -352,7 +362,7 @@ SortedArray(array: [5, 2, 1, 3, 0, 4]).subArray(fromIndex: Array<Int>.Index(2))

### FrequencyTable

#### FrequencyTable(values: valuesArray){ valueToFrequencyClosure }
#### FrequencyTable(values: valuesArray) { valueToFrequencyClosure }

Initialize with values and closure.

Expand All @@ -367,7 +377,7 @@ let wordFrequencies = [
WordFrequency(word: "Ronald", frequency: 1)
]

let frequencyTable = FrequencyTable(values: wordFrequencies){ $0.frequency }
let frequencyTable = FrequencyTable(values: wordFrequencies) { $0.frequency }
// => HandySwift.FrequencyTable<WordFrequency>
```

Expand Down
26 changes: 17 additions & 9 deletions Sources/Extensions/ArrayExtension.swift
Expand Up @@ -9,7 +9,6 @@
import Foundation

public extension Array {

/// Returns a random element from the `Array`.
///
/// - Returns: A random element from the array or `nil` if empty.
Expand All @@ -18,7 +17,6 @@ public extension Array {
let randomIndex = startIndex.advanced(by: Int(randomBelow: self.count))
return self[randomIndex]
}

return nil
}

Expand All @@ -28,18 +26,28 @@ public extension Array {
/// - size: The number of random elements wanted.
/// - Returns: An array with the given number of random elements or `nil` if empty.
public func sample(size: Int) -> [Element]? {

if !isEmpty {
var sampleElements: [Element] = []

size.times {
sampleElements.append(self.sample()!)
}

size.times { sampleElements.append(self.sample()!) }
return sampleElements
}

return nil
}

/// Combines each element with each element of a given array.
///
/// Also known as: Cartesian product.
///
/// - Parameters:
/// - other: Other array to combine the elements with.
/// - Returns: An array of tuples with the elements of both arrays combined.
public func combinations<T>(with other: [T]) -> [(Element, T)] {
var combinations = [(Element, T)]()
self.forEach { elem in
other.forEach { otherElem in
combinations.append((elem, otherElem))
}
}
return combinations
}
}
10 changes: 1 addition & 9 deletions Sources/Extensions/CharacterViewExtension.swift
Expand Up @@ -9,7 +9,6 @@
import Foundation

public extension String.CharacterView {

/// Returns a random character from the `ChracterView`.
///
/// - Returns: A random character from the `CharacterView` or `nil` if empty.
Expand All @@ -28,18 +27,11 @@ public extension String.CharacterView {
/// - size: The number of random characters wanted.
/// - Returns: A `CharacterView` with the given number of random characters or `nil` if empty.
public func sample(size: Int) -> String.CharacterView? {

if !isEmpty {
var sampleElements = String.CharacterView()

size.times {
sampleElements.append(sample()!)
}

size.times { sampleElements.append(sample()!) }
return sampleElements
}

return String.CharacterView()
}

}
9 changes: 0 additions & 9 deletions Sources/Extensions/ColorExtension.swift
Expand Up @@ -7,11 +7,9 @@
//

#if !os(OSX)

import UIKit

extension UIColor {

/// A list of changeable attributes of the UIColor.
///
/// - Red: The red color part of RGB & alpha.
Expand All @@ -30,15 +28,13 @@

/// The HSB & alpha attributes of the `UIColor` instance.
public var hsba: (hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) {

var hsba: (hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) = (0, 0, 0, 0)
getHue(&(hsba.hue), saturation: &(hsba.saturation), brightness: &(hsba.brightness), alpha: &(hsba.alpha))
return hsba
}

/// The RGB & alpha attributes of the `UIColor` instance.
public var rgba: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) {

var rgba: (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) = (0, 0, 0, 0)
getRed(&rgba.red, green: &rgba.green, blue: &rgba.blue, alpha: &rgba.alpha)
return rgba
Expand Down Expand Up @@ -77,7 +73,6 @@
case .brightness:
return change(attribute, to: hsba.brightness + addition)
}

}

/// Creates a new `UIColor` object with the value of a single attribute set to a given value.
Expand All @@ -87,7 +82,6 @@
/// - to: The new value to be set for the attribute.
/// - Returns: The resulting new `UIColor` with the specified change applied.
public func change(_ attribute: ChangeableAttribute, to newValue: CGFloat) -> UIColor { // swiftlint:disable:this cyclomatic_complexity

switch attribute {
case .red, .green, .blue, .alpha:
var newRgba = self.rgba
Expand Down Expand Up @@ -129,8 +123,5 @@
return UIColor(hue: newHsba.hue, saturation: newHsba.saturation, brightness: newHsba.brightness, alpha: newHsba.alpha)
}
}

}


#endif
12 changes: 0 additions & 12 deletions Sources/Extensions/CoreGraphicsExtensions.swift
Expand Up @@ -10,11 +10,9 @@ import Foundation

#if !os(OSX)
import UIKit

// MARK: - iOS/tvOS CGSize Extension

extension CGSize {

/// Returns a new CGSize object with the width and height converted to true pixels on the main screen.
public var inPixels: CGSize {
return inPixels(UIScreen.main)
Expand All @@ -27,35 +25,30 @@ import Foundation
public func inPixels(_ screen: UIScreen) -> CGSize {
return CGSize(width: width * screen.scale, height: height * screen.scale)
}

}


// MARK: - iOS/tvOS CGPoint Extension

extension CGPoint {

/// Returns a new CGPoint object with the x and y converted to true pixels on the main screen.
public var inPixels: CGPoint {
return inPixels(UIScreen.main)
}


/// Returns a new CGPoint object with the x and y converted to true pixels on the given screen.
///
/// - Parameters:
/// - screen: The target screen to convert to pixels for.
public func inPixels(_ screen: UIScreen) -> CGPoint {
return CGPoint(x: x * screen.scale, y: y * screen.scale)
}

}


// MARK: - iOS/tvOS CGRect Extension

extension CGRect {

/// Returns a new CGRect object with the origin and size converted to true pixels on the main screen.
public var inPixels: CGRect {
return inPixels(UIScreen.main)
Expand All @@ -68,17 +61,13 @@ import Foundation
public func inPixels(_ screen: UIScreen) -> CGRect {
return CGRect(origin: origin.inPixels(screen), size: size.inPixels(screen))
}

}


#endif


// MARK: - Shared CGRect Extension

extension CGRect {

/// Creates a new CGRect object from origin zero with given size.
///
/// - Parameters:
Expand All @@ -95,5 +84,4 @@ extension CGRect {
public init(width: CGFloat, height: CGFloat) {
self.init(origin: CGPoint.zero, size: CGSize(width: width, height: height))
}

}
12 changes: 1 addition & 11 deletions Sources/Extensions/DictionaryExtension.swift
Expand Up @@ -9,24 +9,18 @@
import Foundation

extension Dictionary {

/// Initializes a new `Dictionary` and fills it with keys and values arrays.
///
/// - Parameters:
/// - keys: The `Array` of keys.
/// - values: The `Array` of values.
public init?(keys: [Key], values: [Value]) {

guard keys.count == values.count else {
return nil
}

guard keys.count == values.count else { return nil }
self.init()

for (index, key) in keys.enumerated() {
self[key] = values[index]
}

}

/// Merge given `Dictionary` into this `Dictionary` overriding existing values for matching keys.
Expand All @@ -46,16 +40,12 @@ extension Dictionary {
/// - otherDictionary: The other `Dictionary` to merge into this `Dictionary`.
/// - Returns: The new Dictionary with merged keys and values from this and the other `Dictionary`.
public func mergedWith(_ otherDictionary: [Key: Value]) -> [Key: Value] {

var mergedDict: [Key: Value] = [:]

[self, otherDictionary].forEach { dict in
for (key, value) in dict {
mergedDict[key] = value
}
}

return mergedDict
}

}

0 comments on commit 1388035

Please sign in to comment.