Skip to content

Instantly share code, notes, and snippets.

View vikdenic's full-sized avatar

vik vikdenic

  • Chicago, IL
View GitHub Profile
@vikdenic
vikdenic / AppDelegate.swift
Last active March 2, 2016 03:54
Backendless Course, App 1, Lecture 1, Step 5
class AppDelegate: UIResponder, UIApplicationDelegate {
let APP_ID = "YOUR-APPLICATION-ID"
let SECRET_KEY = "YOUR-APPLICATION-IOS-SECRET-KEY"
let VERSION_NUM = "v1"
var backendless = Backendless.sharedInstance()
var window: UIWindow?
@vikdenic
vikdenic / UICollectionView+CellRetrieval.h
Created February 13, 2016 23:01
Objective-C Category to return all cells from a UICollectionView instance
#import "UICollectionView+CellRetrieval.h"
@implementation UICollectionView (CellRetrieval)
-(NSArray *) allCells {
NSMutableArray *cells = [[NSMutableArray alloc] init];
for (NSInteger j = 0; j < [self numberOfSections]; ++j)
{
for (NSInteger i = 0; i < [self numberOfItemsInSection:j]; ++i)
{
@vikdenic
vikdenic / gist:a1f07fee9f319027923a
Created January 28, 2016 03:26
Promises w/ Parse Cloud Code Example
Parse.Cloud.beforeSave("Entry", function(request, response) {
var entry = request.object;
var contest = request.object.get("contest");
var fetchedUser, fetchedContest;
var errorMessage;
entry.get("user").fetch().then(function(result) {
fetchedUser = result;
return contest.fetch();
@vikdenic
vikdenic / gist:eb7bab00295649c081c1
Last active December 8, 2015 18:26
String validation (Swift)
extension String {
func isValidString() -> Bool {
var charSet = NSCharacterSet(charactersInString: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_")
charSet = charSet.invertedSet
let range = (self as NSString).rangeOfCharacterFromSet(charSet)
if range.location != NSNotFound {
@vikdenic
vikdenic / gist:0f95ef77f56fc6439a38
Created December 8, 2015 00:06
Class method on PFUser subclass that throws
// In this example, we will create a class method for our PFUser subclass
// The method will register a new user, but throw certain error types for us to exhaustively handle
// First, we define our errors as an enum that conforms to ErrorType
// Here we anticipate common error cases
enum SignUpError: ErrorType {
case EmptyFields
case TooLong
case TooShort
}
@vikdenic
vikdenic / gist:570060d52fb254a04c98
Created October 30, 2015 05:36
Twitter post with media
if shouldShareToTwitter == true {
if didSaveToTwitter == false {
//In ReviewInfoViewController, we have started a session with logInWithCompletion()
let store = Twitter.sharedInstance().sessionStore
if let userid = store.session()?.userID {
let client = TWTRAPIClient(userID: userid) //we have this from logInWithCompletion() in the previousVC
@vikdenic
vikdenic / VZClassHelper.h
Created September 7, 2015 09:40
Return array of all properties from a specified object of a particular class type
#import "VZClassHelper.h"
#import <objc/runtime.h>
@implementation VZClassHelper
+(NSMutableArray *)allPropertiesFromObject:(NSObject *)object ofType:(Class)class
{
NSMutableArray *array = [NSMutableArray new];
unsigned int count=0;
objc_property_t *props = class_copyPropertyList([object class],&count);
@vikdenic
vikdenic / gist:785d4ae6cdd0bb87956c
Created September 4, 2015 05:05
Add auto-layout constraints programmatically
-(void)constrainSubview:(UIView *)subview toSuperview:(UIView *)superview {
subview.translatesAutoresizingMaskIntoConstraints = NO;
// initialize
NSLayoutConstraint *width =[NSLayoutConstraint
constraintWithItem:subview
attribute:NSLayoutAttributeWidth
relatedBy:0
toItem:superview
attribute:NSLayoutAttributeWidth
@implementation ContactsManager
+(void)requestContactsAccess:(void (^)(BOOL success, ABAddressBookRef addressBook, CFErrorRef error))completionHandler
{
CFErrorRef error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (!granted)
{
-(instancetype)initWithName:(NSString *)name andGeoPoint:(PFGeoPoint *)geoPoint {
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
self = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([CDRegion class]) inManagedObjectContext:appDelegate.managedObjectContext];
self.name = name;
self.longitude = [NSNumber numberWithDouble:geoPoint.longitude];
self.latitude = [NSNumber numberWithDouble: geoPoint.latitude];
return self;
}