Skip to content

Instantly share code, notes, and snippets.

View ranmyfriend's full-sized avatar
🦆
Calm

Ranjith ranmyfriend

🦆
Calm
View GitHub Profile
@ranmyfriend
ranmyfriend / gist:463a3ba8b9aeeb21e2fc
Last active August 29, 2015 14:20
contacts filling API
/* Here You can able to fill the 6k contacts to iPhone default AddressBook.
Its for testing purpose only I created this API.
6000 contacts: 1000 (Steve), 1000 (Tim), 1000 (Kalam), 1000 (Jonathan), 1000 (Vishal), (1000) (Zippr)
*/
- (void)dummyContactsFill {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();
for(int i=0;i<6000;i++) {
@ranmyfriend
ranmyfriend / gist:8d22cf91dc73c929faca
Created May 19, 2015 08:06
Hide the TableView Empty Rows
- (void)pr_hideEmptySeparators {
UIView *emptyView = [[UIView alloc] initWithFrame:CGRectZero];
emptyView.backgroundColor = [UIColor clearColor];
[self.tableView setTableFooterView:emptyView];
}
@ranmyfriend
ranmyfriend / gist:d73da76d4911913768b2
Created July 14, 2015 05:09
We can't simply cross check the index value with nil! <NSNotFound>
NSArray *array = @[@(1),@(2),@(3)];
NSInteger index = [array indexOfObject:@(4)];
/** @abstract: we can’t compare the index and also we can’t able to check whether it is a nil value or not?
Coz, its a Long Long integer. if you print the index on debugger window, you will get this value: 9223372036854775807
Thats why we are checking with NSNotFound
If you don't don the defence check you will crash. Its safety check!.
*/
if(index == NSNotFound) {
// index value is not found !
// Use the NSAssert for handling the value or !value here.
- (void)addConstraints {
[self.view removeConstraints:self.view.constraints];
NSDictionary *views = NSDictionaryOfVariableBindings(_contactImageProperty,_peopleAllowLabelProperty,_shareCodesDefaultMessageLabelProperty,_continueBtnProperty);
_contactImageProperty.translatesAutoresizingMaskIntoConstraints = NO;
_peopleAllowLabelProperty.translatesAutoresizingMaskIntoConstraints = NO;
_shareCodesDefaultMessageLabelProperty.translatesAutoresizingMaskIntoConstraints = NO;
_continueBtnProperty.translatesAutoresizingMaskIntoConstraints = NO;
// contactImageProperty
@ranmyfriend
ranmyfriend / Crash at PFDateFormatter.m
Created October 15, 2015 09:35
CallStack of Crash is Happening in PFDateFormmater.m class file.
2015-10-15 14:12:40.898 Contacts[47206:5612488] -[__NSTaggedDate UTF8String]: unrecognized selector sent to instance 0xe41bbcf9e80c4dd3
(lldb) po string
2015-10-15 08:42:40 +0000
(lldb) po [string isKindOfClass:[NSString class]]
false
2015-10-15 15:01:53.762 Contacts[47206:5612488] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSTaggedDate UTF8String]: unrecognized selector sent to instance 0xe41bbcf9e80c4dd3'
*** First throw call stack:
(
@ranmyfriend
ranmyfriend / GenericsExperiement
Created December 15, 2016 21:23
Initialize Struct class using Generics and work for b->child1,child2. So if you access b you can get b.meta and b.response<home,login,signup>
/*-------------Initialize Struct class using Generics and bounding for b->child1,child2-----*/
struct b<T> {
var resp: T?
var meta: metaResp?
init?(input:Dictionary<String,Any>,resp: T) {
self.resp = resp
let bin:[String:Any] = input["base"] as! [String : Any]
meta = metaResp.init(input: bin["meta"] as! Dictionary<String, Any>)
@ranmyfriend
ranmyfriend / InputScenePreview.Swift
Created January 3, 2017 20:54
To view the Viewcontroller child views as Live using Playground support. People who want to learn Visual Format Language(VFL) and try out how it look like. This will save lot of developer Time
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
class InputScene : UIViewController {
var emailTxtField:UITextField?
var passwordTxtField:UITextField?
@ranmyfriend
ranmyfriend / Dictionary Additions
Created March 4, 2017 13:02
We create a special subscript for nested `[String:Any]` dictionaries that also has a getter
// Created - Ranjit
import Foundation
//: ### Subscript Solution
//: We create a special subscript for nested `[String:Any]` dictionaries that also has a getter:
extension Dictionary {
subscript(jsonDict key: Key) -> [String:Any]? {
@ranmyfriend
ranmyfriend / String+Validation
Created March 6, 2017 21:47
Phone Number validation in Swift 3
extension String {
public func isPhone()->Bool {
if self.isAllDigits() == true {
let phoneRegex = "[235689][0-9]{6}([0-9]{3})?"
let predicate = NSPredicate(format: "SELF MATCHES %@", phoneRegex)
return predicate.evaluate(with: self)
}else {
return false
}
@ranmyfriend
ranmyfriend / One Time Password View.swift
Created March 10, 2017 22:46
Phone Number - OneTimePassword Inputview design code and the fancy here is cursor going forward and backward is awesome.
import UIKit
protocol OTPInputViewProtocol:class {
func digitsInputViewCompletion()
}
fileprivate let MAX_COUNT_DOWN_TIME:Int = 120
class ADOTPInputView: UIView,UITextFieldDelegate {