Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Aleksey Lobanov alobanov

🏠
Working from home
Block or report user

Report or block alobanov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alobanov
alobanov / gist:7615579
Last active Dec 29, 2015
Save image to Camera Roll
View gist:7615579
UIImageWriteToSavedPhotosAlbum(_currentVC.imageView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
// Was there an error?
if (error != NULL)
{
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle: @"Error, try again"];
@alobanov
alobanov / SimpleViewController.swift
Last active Jan 22, 2016
Simple creating viewcintroller instance by instantiateViewControllerWithIdentifier
View SimpleViewController.swift
class SimpleViewController: UIViewController, StoryboardInstantiable{
typealias ViewController = SimpleViewController
static var storyboardID: String { get { return "SimpleViewController" } }
override func viewDidLoad() {
super.viewDidLoad()
}
}
@alobanov
alobanov / UIViewController+StoryboardInstantiable.h
Last active Jan 23, 2016
Simple instantiateViewControllerWithIdentifier category
View UIViewController+StoryboardInstantiable.h
#import <UIKit/UIKit.h>
@protocol StoryboardInstantiable <NSObject>
+ (NSString *)storyboardID;
@end
@interface UIViewController (StoryboardInstantiable)
@alobanov
alobanov / HudItemExample.m
Created Feb 7, 2017
Example, how to use HUDItem
View HudItemExample.m
// создаём элемент худа
HUDItem *item = [HUDItem itemWithTitle:@”Title” andDetail:@”Test”];
// Возможные настройки
item.hideDelay = 2.0; // время показа
item.imageType = HUDImage_SadFace; // картинка
item.dimBackground = YES; // затемнять фон
item.mode = ProgressHUDModeText; // тип hud’a
// Показать созданый item
@alobanov
alobanov / PublicMethods.m
Created Feb 7, 2017
ALHudManager public methods
View PublicMethods.m
- (void) setProgress:(float) value;
- (void) setDetailText:(NSString *) text;
- (void) updateHudView:(UIView *) hudView;
- (void) showAlwaysOnTop;
View HUDItemImage.m
HUDItem *item = [HUDItem itemWithTitle:@”Nice heart” andDetail:@”Smile bitch!”];
item.hudCustomImagePath = @”hudTest.png”;
item.hideDelay = 7.0;
[ALHUDManager showHUD:item];
@alobanov
alobanov / MacrosALLocalized.m
Created Feb 7, 2017
Все макросы для работы с менеджером
View MacrosALLocalized.m
// init localized manager
ALLocalizedInit
// Update current index by index
ALLocalizationSetLanguageByIndex(language)
// set language (example "ru","en")
ALLocalizationSetLanguage(language)
// return "ru","en" and etc.
View ExampleMapping.swift
let pred = NSPredicate(format: "slug = 'default'")
if let item: FolderData = databaseProvider.firstObject(type: DataModelType.folderData, predicate: pred) {
let realm = RealmConfigurator.shared.reamInstance()
try! realm.write {
item.mapping(map: Map(mappingType: .fromJSON, JSON: ["test": "Whaaaat?"]))
}
}
@alobanov
alobanov / Array+Sort.swift
Last active Aug 22, 2017
Array sorting by predefined sorting ids list
View Array+Sort.swift
extension Array {
func sortByArray<T, Z: Hashable>(of ids:[Z],
keyType: Z.Type,
idClosure: (_ obj: T) -> (Z)) -> [T] {
var dict = [Z: T]()
guard let arr = self as? [T] else {
return []
}
@alobanov
alobanov / factory.swift
Last active Oct 1, 2017
🏭 Фабричный метод — это порождающий паттерн проектирования, который определяет общий интерфейс для создания объектов в суперклассе, позволяя подклассам изменять тип создаваемых объектов.
View factory.swift
//: Playground - noun: a place where people can play
import UIKit
// Models
struct UniverseType {
static let marvel = MarvelHero.self
static let dc = DCHero.self
}
You can’t perform that action at this time.