Skip to content

Instantly share code, notes, and snippets.

@YGeorge
YGeorge / UIView+YGUtilities.m
Created March 13, 2016 13:42
UIView+YGUtilities
//
// NSDate+YGUtilities.m
// YGUtilities (https://github.com/YGeorge/YGUtilities)
//
// Created by George on 26.02.16.
// Copyright (c) 2016 George Ymydykov. All rights reserved.
//
#import "UIView+YGUtilities.h"
Choose 'login' and 'Keys'
@YGeorge
YGeorge / ViewController.m
Created November 30, 2015 10:33
UITextField percent
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField == self.percentTextField) {
NSString *text = textField.text;
if ([string length] == 0 && range.length > 0) { //if delete last symbol
if (text.length > 0) {
text = [text substringToIndex:[text length] - 2];
textField.text = text.length > 0 ? [NSString stringWithFormat:@"%@%%",text] : @"";
}
} else {
text = [text stringByReplacingCharactersInRange:range withString:string];
@YGeorge
YGeorge / YGFileService.m
Last active September 18, 2015 10:43
Call bunch of requests (blocks)
+ (void)deleteDocumentsForFiles:(NSArray *)files forAccount:(NSString *)accountID success:(void (^)())success failure:(void (^)(NSError *error))failure {
__block NSInteger successDeleting = 0;
__block NSInteger failureDeleting = 0;
dispatch_group_t deleteDocumentGroup = dispatch_group_create();
for (YGFile *file in files) {
dispatch_group_enter(deleteDocumentGroup);
[YGFileService deleteDocument:file.documentID forAccount:accountID success:^{
DDLogVerbose(@"Delete document %@ success", file.documentID);
successDeleting++;
DDLogVerbose(@"successDeleting %d", successDeleting);
@YGeorge
YGeorge / Example.m
Created September 7, 2015 14:14
NSMutableArray+YGHelper
[sources removeObjectsWithPredicate:^BOOL(id obj){
LCFTSource *source = (LCFTSource *)obj;
return [self.hiddenSourceIDs containsObject:source.sourceID];
}];
@YGeorge
YGeorge / UIKeyboardFrameEndUserInfoKey
Created September 1, 2015 07:35
Correct keyboard frame
- (void)keyboardWillShow:(NSNotification *)notification {
CGRect keyboardFrame = [[notification userInfo][UIKeyboardFrameEndUserInfoKey] CGRectValue];
self.textViewBottomConstraint.constant = keyboardFrame.size.height - self.tabBarController.tabBar.frame.size.height;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
[self.view addGestureRecognizer:singleTap];
[UIView animateWithDuration:[notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]
delay:0
options:(UIViewAnimationOptions) [[notification userInfo][UIKeyboardAnimationCurveUserInfoKey] integerValue]
@YGeorge
YGeorge / Group by date
Last active August 29, 2015 14:23
Group by date
NSMutableArray *resultArray = [NSMutableArray new];
NSMutableOrderedSet *orderedDates = [NSMutableOrderedSet new];
for (LCFeed *feed in feeds) {
[orderedDates addObject:feed.createdDateString];
}
for (NSString *name in orderedDates) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"createdDateString = %@", name];
NSArray *groupOfFeeds = [feeds filteredArrayUsingPredicate:predicate];
[resultArray addObject:groupOfFeeds];
@YGeorge
YGeorge / UIImage+YGSize.h
Last active September 7, 2015 14:17
UIImage+Size category
//
// UIImage+YGSize.h
//
#import <Foundation/Foundation.h>
@interface UIImage (YGSize)
+ (UIImage *)sizedImageWithName:(NSString *)name;
@end
@YGeorge
YGeorge / CLLocationManagerStartKit.m
Last active August 29, 2015 14:14
CLLocationManager startkit iOS 7,8
// didFinishLaunchingWithOptions or viewDidLoad:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
NSLog(@"authorizationStatus: %d", status);
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined &&
@YGeorge
YGeorge / StrongAndWeak
Created July 22, 2014 05:27
Obj-C Strong and Weak references
Представьте, что наш объект — это собака. Собака хочет «убежать» (освободить память).
Сильный указатель — это поводок с ошейником. Пока поводок прицеплен к ошейнику, собака не убежит.
Если 5 человек прицепят 5 поводков к одному ошейнику (5 указателей на 1 объект) — собака не убежит до тех пор,
пока не отцепят все 5 поводков.
А слабые указатели — это дети, которые тычут пальцем на собаку и кричат: «Ух ты, собака!»
Пока собака на поводке, они могут тыкать («указывать на объект») сколько угодно.
Но если отсоединить все поводки, то собака убежит, независимо от того, сколько детей тычут в неё пальцем.