-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from AckeeCZ/jo/new_stuff
New stuff
- Loading branch information
Showing
11 changed files
with
183 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Foundation | ||
|
||
precedencegroup ConditionalAssignmentPrecedence { | ||
associativity: left | ||
assignment: true | ||
higherThan: AssignmentPrecedence | ||
} | ||
|
||
infix operator =?: ConditionalAssignmentPrecedence | ||
|
||
public func =?<T>(variable: inout T, value: T?) { | ||
if let v = value { | ||
variable = v | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Foundation | ||
|
||
/// Safe subscript for collections | ||
public protocol SafeRandomAccessCollection: RandomAccessCollection { | ||
subscript(safe index: Int) -> Iterator.Element? { get } | ||
} | ||
|
||
extension Array: SafeRandomAccessCollection { | ||
public subscript(safe index: Int) -> Iterator.Element? { | ||
return indices ~= index ? self[index] : nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import UIKit | ||
|
||
extension UIImage { | ||
|
||
// taken from http://stackoverflow.com/questions/10850184/ios-image-get-rotated-90-degree-after-saved-as-png-representation-data | ||
public func fixedOrientation() -> UIImage { | ||
guard imageOrientation != .up else { return self } | ||
|
||
UIGraphicsBeginImageContextWithOptions(size, false, scale) | ||
draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height)) | ||
let normalizedImage = UIGraphicsGetImageFromCurrentImageContext()! | ||
UIGraphicsEndImageContext() | ||
|
||
return normalizedImage | ||
} | ||
|
||
public func resized(maxDimension: CGFloat) -> UIImage? { | ||
let isLandscape = size.width > size.height | ||
|
||
let newSize: CGSize | ||
if isLandscape { | ||
newSize = CGSize(width: maxDimension, height: (size.height / size.width) * maxDimension) | ||
} else { | ||
newSize = CGSize(width: (size.width / size.height) * maxDimension, height: maxDimension) | ||
} | ||
|
||
UIGraphicsBeginImageContextWithOptions(newSize, false, scale) | ||
draw(in: CGRect(origin: .zero, size: newSize)) | ||
let newImage = UIGraphicsGetImageFromCurrentImageContext() | ||
UIGraphicsEndImageContext() | ||
return newImage | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import UIKit | ||
|
||
public extension UISearchBar { | ||
public var textField: UITextField! { return value(forKey: "searchField") as! UITextField } | ||
} |
30 changes: 30 additions & 0 deletions
30
ACKategories/Classes/UIViewController+SafeAreaCompat.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import UIKit | ||
|
||
@available(iOS 9.0, *) | ||
extension UIViewController { | ||
private enum Keys { | ||
static var safeArea: UInt8 = 0 | ||
} | ||
|
||
/// Layout guide compatibility extension for iOS 11 safe area | ||
/// | ||
/// On iOS 11+ is the same as `view.safeAreaLayoutGuide`. | ||
/// | ||
/// On older systems it fallbacks to `topLayoutGuide.bottom` and `bottomLayoutGuide.top`, side constraints are equal to superview. | ||
public var safeArea: UILayoutGuide { | ||
if #available(iOS 11.0, *) { | ||
return view.safeAreaLayoutGuide | ||
} else { | ||
if let layoutGuide = objc_getAssociatedObject(self, &Keys.safeArea) as? UILayoutGuide { return layoutGuide } | ||
|
||
let layoutGuide = UILayoutGuide() | ||
view.addLayoutGuide(layoutGuide) | ||
layoutGuide.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true | ||
layoutGuide.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor).isActive = true | ||
layoutGuide.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true | ||
layoutGuide.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true | ||
objc_setAssociatedObject(self, &Keys.safeArea, layoutGuide, .OBJC_ASSOCIATION_ASSIGN) | ||
return layoutGuide | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Foundation | ||
|
||
extension UserDefaults { | ||
private enum Keys { | ||
static let deviceID = "ud_device_id_b8cb6644-43fa-4bc4-a4f3-23f9e5d25c8f" | ||
} | ||
|
||
public var deviceID: String { | ||
if let result = string(forKey: Keys.deviceID) { | ||
return result | ||
} | ||
|
||
let newDeviceID = NSUUID().uuidString | ||
|
||
set(newDeviceID, forKey: Keys.deviceID) | ||
synchronize() | ||
|
||
return newDeviceID | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters