Skip to content

Instantly share code, notes, and snippets.

View alobanov's full-sized avatar
🏠
Working from home

Aleksey Lobanov alobanov

🏠
Working from home
View GitHub Profile
@alobanov
alobanov / Array+Sort.swift
Last active August 22, 2017 14:04
Array sorting by predefined sorting ids list
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 []
}
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 / MacrosALLocalized.m
Created February 7, 2017 20:10
Все макросы для работы с менеджером
// init localized manager
ALLocalizedInit
// Update current index by index
ALLocalizationSetLanguageByIndex(language)
// set language (example "ru","en")
ALLocalizationSetLanguage(language)
// return "ru","en" and etc.
@alobanov
alobanov / HUDItemImage.m
Created February 7, 2017 20:08
Set custom image
HUDItem *item = [HUDItem itemWithTitle:@”Nice heart” andDetail:@”Smile bitch!”];
item.hudCustomImagePath = @”hudTest.png”;
item.hideDelay = 7.0;
[ALHUDManager showHUD:item];
@alobanov
alobanov / PublicMethods.m
Created February 7, 2017 20:07
ALHudManager public methods
- (void) setProgress:(float) value;
- (void) setDetailText:(NSString *) text;
- (void) updateHudView:(UIView *) hudView;
- (void) showAlwaysOnTop;
@alobanov
alobanov / HudItemExample.m
Created February 7, 2017 20:05
Example, how to use HUDItem
// создаём элемент худа
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 / UIViewController+StoryboardInstantiable.h
Last active January 23, 2016 13:42
Simple instantiateViewControllerWithIdentifier category
#import <UIKit/UIKit.h>
@protocol StoryboardInstantiable <NSObject>
+ (NSString *)storyboardID;
@end
@interface UIViewController (StoryboardInstantiable)
@alobanov
alobanov / SimpleViewController.swift
Last active January 22, 2016 19:17
Simple creating viewcintroller instance by instantiateViewControllerWithIdentifier
class SimpleViewController: UIViewController, StoryboardInstantiable{
typealias ViewController = SimpleViewController
static var storyboardID: String { get { return "SimpleViewController" } }
override func viewDidLoad() {
super.viewDidLoad()
}
}
@alobanov
alobanov / gist:7615579
Last active December 29, 2015 04:29
Save image to Camera Roll
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"];