Skip to content

Instantly share code, notes, and snippets.

@aibobrov
aibobrov / xcode_todo_fixme_error.sh
Created September 21, 2018 15:02
Build script for Xcode to add TODO, FIXME, ERROR highlighting
TAGS="TODO:|FIXME:"
ERRORTAG="ERROR:"
OUTPUT=$(find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/")
ECHO "$OUTPUT"
if [[ $OUTPUT == *" error: "* ]]
then
exit 1
fi
@aibobrov
aibobrov / SelfSizedTableView.swift
Created September 17, 2018 14:09
Self sized UITableView
import UIKit
class SelfSizedTableView: UITableView {
lazy var heightConstraint: NSLayoutConstraint = {
let constraint = NSLayoutConstraint(item: self, attribute: .height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: bounds.height)
return constraint
}()
override init(frame: CGRect, style: UITableViewStyle) {
super.init(frame: frame, style: style)
@aibobrov
aibobrov / PolygonMaskedView.swift
Created September 17, 2018 14:09
View masked by a rounded polygon
import UIKit
extension UIBezierPath {
/// Makes a bezier path which can be used for a rounded polygon
/// layer
///
/// - Parameters:
/// - rect: uiview rect bounds
/// - lineWidth: width border line
/// - sides: number of polygon's sides
@aibobrov
aibobrov / SteppedSlider.swift
Created September 17, 2018 14:06
Simple SteppedSlider in swift. Subclass of UISlider
import UIKit
@IBDesignable
class SteppedSlider: UISlider {
@IBInspectable var stepSize: Int = 1
@IBInspectable var normalThumbImage: UIImage? {
get {
return thumbImage(for: .normal)
}
@aibobrov
aibobrov / CustomXibView.swift
Created September 17, 2018 14:05
Subclass of UIView for comfort creating custom views from Xib
import UIKit
/*
Usage:
1. Create new xib file.
2. Create new swift file containg class subclassed from CustomXibView.
3. In xib set recently created class name as File's owner.
*/
@aibobrov
aibobrov / ImageView.swift
Created September 17, 2018 13:59
IBDesignable subclass of UIImageView
import UIKit
@IBDesignable
class ImageView: UIImageView {
// MARK: - Layer stuff
@IBInspectable
var cornerRadius: CGFloat {
get {
return layer.cornerRadius
@aibobrov
aibobrov / Button.swift
Created September 17, 2018 13:58
IBDesignable subclass of UIButton
import UIKit
@IBDesignable
class Button: UIButton {
// MARK: - Layer stuff
@IBInspectable
var cornerRadius: CGFloat {
get {
return layer.cornerRadius
@aibobrov
aibobrov / View.swift
Created September 17, 2018 13:57
IBDesignable subclass of UIView
import UIKit
@IBDesignable
public class View: UIView {
// MARK: - Layer stuff
@IBInspectable
public var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
@aibobrov
aibobrov / KeyboardManager.swift
Last active October 5, 2018 22:56
Keyboard manager that helps to manage keyboard events
import UIKit
open class KeyboardManager: NSObject {
public enum KeyboardEvent {
case willShow
case didShow
case willHide
case didHide
case willChangeFrame
case didChangeFrame
@aibobrov
aibobrov / Logging.swift
Created September 14, 2018 08:39
Simple logger for Swift
import Foundation
fileprivate extension String {
var sourceFileName: String {
let fileName = self.components(separatedBy: "/").last?.split(separator: ".").first ?? ""
return String(fileName)
}
}
public class Logger {