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 / registry.m
Created December 22, 2016 11:22
Registry pattern for singleton factory
+ (instancetype)sharedInstance {
static dispatch_once_t once;
static NSMutableDictionary *sharedInstances;
dispatch_once(&once, ^{
// Creating of the container for shared instances for different classes
sharedInstances = [NSMutableDictionary new];
});
id sharedInstance = nil;
@ManWithBear
ManWithBear / create-iso.sh
Last active December 10, 2016 12:03 — forked from julianxhokaxhiu/create-iso.sh
Simple bash script to create a Bootable ISO from macOS Sierra Install Image from Mac App Store
#!/bin/bash
#
# Credits to fuckbecauseican5 from https://www.reddit.com/r/hackintosh/comments/4s561a/macos_sierra_16a238m_install_success_and_guide/
# Adapted to work with the official image available into Mac App Store
#
# Enjoy!
hdiutil attach /Applications/Install\ macOS\ Sierra.app/Contents/SharedSupport/InstallESD.dmg -noverify -nobrowse -mountpoint /Volumes/install_app
hdiutil create -o /tmp/Sierra.cdr -size 7316m -layout SPUD -fs HFS+J
hdiutil attach /tmp/Sierra.cdr.dmg -noverify -nobrowse -mountpoint /Volumes/install_build
@ManWithBear
ManWithBear / swiftlint.yml
Last active April 21, 2017 09:44
Common used rules for swiftlint
included:
- {Project folder}
- {Project test folder}
excluded:
- {Project folder}/Extensions/UIImage+Assets.swift # automatically generated file
opt_in_rules:
- closure_spacing # closure should have single space inside each brace
- empty_count # prefer isEmpty over comparing to 0
- number_separator # underscore should be used as thousand separator in large decimal numbers
disabled_rules:
@ManWithBear
ManWithBear / UITableViewCell+ParentTableView.m
Created November 30, 2016 15:58
Find first tableView in hierarchy
- (UITableView *)parentTableView {
// iterate up the view hierarchy to find the table containing this cell/view
UIView *aView = self.superview;
while(aView != nil) {
if([aView isKindOfClass:[UITableView class]]) {
return (UITableView *)aView;
}
aView = aView.superview;
}
return nil; // this view is not within a tableView
@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;
});
}
@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 / 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 / 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 / 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 / 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