Skip to content

Instantly share code, notes, and snippets.

View casspangell's full-sized avatar

mondousage casspangell

View GitHub Profile
import UIKit
import WebKit
final class ReCAPTCHAViewController: UIViewController {
private var webView: WKWebView!
private let viewModel: ReCAPTCHAViewModel
init(viewModel: ReCAPTCHAViewModel) {
self.viewModel = viewModel
@casspangell
casspangell / tableview.m
Last active October 22, 2015 21:14
Load Tableview Thumbs
//Taken from and used with:
// http://stackoverflow.com/questions/16663618/async-image-loading-from-url-inside-a-uitableview-cell-image-changes-to-wrong
////////////////////
//With SDWebImage //
////////////////////
(don't use the below method. This one is king.)
//Import the goods and use PODS
// pod 'SDWebImage', '~> 3.7'
@casspangell
casspangell / blocks.m
Last active October 22, 2015 20:06
Weak Self in Blocks
@implementation XYZBlockKeeper
- (void)configureBlock {
self.block = ^{
[self doSomething]; // capturing a strong reference to self
// creates a strong reference cycle
};
}
...
@end
@casspangell
casspangell / saving.m
Created October 21, 2015 19:43
Saving Data to NSUserDefaults
// Given `notes` contains an array of Note objects
//Archive
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:notes];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"notes"];
//Unarchive
NSData *notesData = [[NSUserDefaults standardUserDefaults] objectForKey:@"notes"];
NSArray *notes = [NSKeyedUnarchiver unarchiveObjectWithData:notesData];
@casspangell
casspangell / Google_geocode.m
Last active October 16, 2015 21:07
iOS MapKit and Google Map API Geocoding
//GOOGLE GEOCODING
//Get Address String from Google API CLLocation Lat/Lon
-(void) googleReverseGeocode :(CLLocation *)location {
[[GMSGeocoder geocoder] reverseGeocodeCoordinate:location.coordinate completionHandler:
^(GMSReverseGeocodeResponse *response, NSError *error){
if (error) {
@casspangell
casspangell / CompletionBlocksWithBOOL.m
Last active September 15, 2015 17:50
Completion Block with Data Return
.h = - (void)signInAccountWithUserName:(NSString *)userName
password:(NSString *)password
completion:(void (^)(BOOL success))completionBlock;
.m = - (void)signInAccountWithUserName:(NSString *)userName
password:(NSString *)password
completion:(void (^)(BOOL success))completionBlock
{
// Notice that we are passing a BOOL back to the completion block.
if (completionBlock != nil) completionBlock(loginSuccessful);
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[GMSServices provideAPIKey:@"AIzaSyAZWKELBYsRrFTjmd572Wh2iLpB92tZH2o"];
// self.dynamicsController = drawerVC;
// self.window.rootViewController = self.dynamicsController;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
WelcomeViewController *welcomeVC = [WelcomeViewController new];
@casspangell
casspangell / AppDelegate.h
Last active September 17, 2015 00:11
Adding, Removing, Updating Elements to CoreData
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@casspangell
casspangell / language.m
Created June 29, 2015 20:30
Return all languages used in app
// Return all languages set in app
// The first language is NULL (?)
-(NSMutableArray*)getLanguages {
NSArray *languageArr = [[NSBundle mainBundle] localizations];
for ( int i=1; i<[languageArr count]; i++) {
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en"];
NSString *lang = [locale displayNameForKey:NSLocaleIdentifier value:[languageArr objectAtIndex:i]];
[self.languageArray addObject:lang];
@casspangell
casspangell / NSBundle+RunTimeLanguage.h
Last active August 29, 2015 14:23
Setting iOS localization on the fly
#import <Foundation/Foundation.h>
#define RUNTIME_LANGUAGE_STORAGE @"runtimeLanguageStorage"
#define RunTimeLanguageEnglish @"en"
#define RunTimeLanguageSpanish @"es-MX"
#undef NSLocalizedString
#define NSLocalizedString(key, comment) [[NSBundle mainBundle] runTimeLocalizedStringForKey:(key) value:@"" table:nil]
#define setLanguage(x) [[NSUserDefaults standardUserDefaults] setObject:x forKey:RUNTIME_LANGUAGE_STORAGE]; [[NSUserDefaults standardUserDefaults] synchronize];