Skip to content

Instantly share code, notes, and snippets.

@Eridana
Eridana / 1) ExpandableTableView.swift
Last active November 8, 2018 13:55
Expandable UITableView
import UIKit
class ExpandableObject {
public var subItems = [ExpandableObject]()
public var title: String?
public var isExpanded: Bool = false
public var isChild: Bool = false
public var cellIdentifier: String?
public var canExpand: Bool {
@Eridana
Eridana / Select photo from galleryor take a new
Created March 3, 2016 12:07
Select photo from galleryor take a new
- (IBAction)addPhotoTap:(id)sender {
UIAlertController* alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* fromGallery = [UIAlertAction actionWithTitle:@"Загрузить из фотоальбома" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
#pragma mark - UIScrolViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pageWidth = scrollView.frame.size.width;
float fractionalPage = scrollView.contentOffset.x / pageWidth;
NSInteger page = lround(fractionalPage);
if (page == 0) {
@Eridana
Eridana / gist:5285c2bcdba69f2f30bc
Last active October 29, 2015 09:02
get CNContacts from Contacts.framework (objective-c)
#if __IPHONE_OS_VERSION_MAX_ALLOWED > 80000
//ios 9+
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (granted == YES) {
NSMutableArray *contacts = [NSMutableArray new];
NSArray *keys = @[CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPhoneNumbersKey, CNContactImageDataKey];
NSString *containerId = store.defaultContainerIdentifier;
NSPredicate *predicate = [CNContact predicateForContactsInContainerWithIdentifier:containerId];
NSError *error;
@Eridana
Eridana / iOS get IpAddress
Created October 23, 2015 05:29
iOS get IpAddress (works with simulator/device)
#include <ifaddrs.h>
#include <arpa/inet.h>
#pragma mark - Get Ip Address
- (NSString *)getIpAddress
{
NSString *address = @"error";
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
@Eridana
Eridana / XmppManager.h
Last active October 10, 2018 12:36
iOS XMPPFramework
//
// XmppManager.h
//
//
//
#import <Foundation/Foundation.h>
@protocol XmppChatDelegate <NSObject>
- (void)didReceiveMessage:(NSDictionary *)msgDict;
@Eridana
Eridana / Get "Today" or "Yesterday" from NSDate
Created March 31, 2015 10:25
Get "Today" or "Yesterday" from NSDate
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"ru_RU"];
[dateFormatter setLocale:locale];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
dateFormatter.doesRelativeDateFormatting = YES;
_dateAsString = [dateFormatter stringFromDate:_date];
@Eridana
Eridana / Sorting array of custon objects by date property
Created March 13, 2015 06:18
Sorting array of custon objects by date property
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"thisIsTheNameOfYourDateProperty" ascending:NO];
NSArray *orderedArray = [arrayOfCustomObjects sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
@Eridana
Eridana / Generate random unique string value
Last active August 29, 2015 14:16
Generate random unique string value
NSTimeInterval today = [[NSDate date] timeIntervalSince1970];
NSString *intervalString = [NSString stringWithFormat:@"%f", today];
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[intervalString doubleValue]];
NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyyMMddhhmm"];
NSString *strValue = [formatter stringFromDate:date];
@Eridana
Eridana / UITextField phone string format
Created February 27, 2015 08:34
UITextField phone string format
_textField.delegate = self (UITextFieldDelegate)
- (NSMutableString *)filteredPhoneStringFromString:(NSString *)string withFilter:(NSString *)filter
{
NSUInteger onOriginal = 0, onFilter = 0, onOutput = 0;
char outputString[([filter length])];
BOOL done = NO;
while(onFilter < [filter length] && !done)
{