Skip to content

Instantly share code, notes, and snippets.

View ManWithBear's full-sized avatar
🐻
Bear with it

Denis Bogomolov ManWithBear

🐻
Bear with it
View GitHub Profile
@ManWithBear
ManWithBear / gitflow.txt
Created May 12, 2016 08:08
Git flow model
git checkout develop
git merge --squash feature/...
git commit -am '#issue comment'
git push origin develop
git branch -D feature/...
git push origin :feature/...
In result flow like:
* <1234567> 2016-05-06 [dev1] (HEAD, origin/develop, develop) version bump
| * <1234567> 2016-05-06 [dev1] (tag: 1.52, master, origin/master) Merge branch 'develop'
@ManWithBear
ManWithBear / UIResponder.swift
Last active July 8, 2019 11:08
Fast way to get firstResponder
import UIKit
private weak var _currentFirstResponder: UIResponder? = nil
extension UIResponder {
class func mwb_firstResponder() -> UIResponder? {
_currentFirstResponder = nil
// If you trying send action to nil, it will automatically called on first responder
UIApplication.shared.sendAction(#selector(mwb_findFirstResponder), to: nil, from: nil, for: nil)
return _currentFirstResponder
@ManWithBear
ManWithBear / String2Enum.swift
Last active November 14, 2016 11:32 — forked from jckarter/gist:53fcd4046e2857bd315b
Optional chaining raw value conversion
extension String {
func toEnum<Enum: RawRepresentable where Enum.RawValue == String>() -> Enum? {
return Enum(rawValue: self)
}
}
enum Segue: String {
case Foo
case Bar
}
@ManWithBear
ManWithBear / NSLayoutConstraints debug
Created October 18, 2016 11:48
Help to understand layout issues
1. Symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints.
2. Add debug command:
- ObjC: po [[UIWindow keyWindow] _autolayoutTrace]
- Swift: expr -l objc++ -O -- [[UIWindow keyWindow] _autolayoutTrace]
3. Colorfy bad views:
expr ((UIView *)0x7f9ea3d43410).backgroundColor = [UIColor redColor]
@ManWithBear
ManWithBear / Swiftgen scripts
Created October 24, 2016 11:29
Script for xcasset enums regeneration
Script:
if which swiftgen >/dev/null; then
swiftgen images ${SCRIPT_INPUT_FILE_0} --output ${SCRIPT_OUTPUT_FILE_0}
else
echo "SwiftGen does not exist, download from https://github.com/AliSoftware/SwiftGen"
fi
Input:
$(SRCROOT)/{Project Name}/Assets.xcassets
@ManWithBear
ManWithBear / Marks2Warnings.sh
Created October 24, 2016 11:34
Create warnings for specified marks ("TODO:" and "FIXME:")
TAGS="TODO:|FIXME:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
@ManWithBear
ManWithBear / UITableView+Generic.swift
Created October 25, 2016 12:40
Wrap common calls on tableview in generic way
protocol NibLoadable { }
extension NibLoadable where Self: UIView {
static var nibName: String {
return String(describing: self)
}
}
extension UITableViewCell: NibLoadable { }
protocol Reusable { }
extension Reusable where Self: UIView {
@ManWithBear
ManWithBear / OCLint.sh
Created November 8, 2016 10:14
OCLint script for xcode
if [ -f ~/.bash_profile ]; then
source ~/.bash_profile
fi
hash oclint &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "oclint not found, analyzing stopped"
exit 1
fi
@ManWithBear
ManWithBear / CustomStringConvertible.swift
Created November 20, 2016 17:42
Extension to CustomStringConvertible for default description providing using reflection.
extension CustomStringConvertible {
var description : String {
var description: String = ""
if self is AnyObject {
description = "***** \(self.dynamicType) - <\(unsafeAddressOf((self as! AnyObject)))>***** \n"
} else {
description = "***** \(self.dynamicType) *****\n"
}
let selfMirror = Mirror(reflecting: self)
for child in selfMirror.children {
@ManWithBear
ManWithBear / TableHeaderView.m
Created November 21, 2016 10:30
Fix problem with wrong tableHeaderView height
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// Give system time to properly recalculate tableHeaderView height and update it
// Otherwise wrong height appear on iOS 10
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.tableView.tableHeaderView = self.tableView.tableHeaderView;
});
}