Skip to content

Instantly share code, notes, and snippets.

View jungchris's full-sized avatar
🏠
Working from home

Chris Jungmann jungchris

🏠
Working from home
View GitHub Profile
@jungchris
jungchris / SponsorDetailVC.m
Last active August 29, 2015 14:27
ViewDidLoad Sets View Using indexOfIdInOrganizationsArray
- (void)viewDidLoad {
[super viewDidLoad];
// NSLog(@"Sponsor #: %li", (long)self.selectedRow);
// set view
NSInteger orgIndex = [SharedConferenceObject indexOfIdInOrganzationsArray:[NSNumber numberWithInteger:self.selectedRow]];
if ((NSNotFound == orgIndex) || (orgIndex >= [SharedConferenceObject.organizationsArray count])) {
// there's a problem ...
NSLog(@"CATCH: SponsorDetailVC array index notFound/bounds for selectedRow: %lu", (long)self.selectedRow);
} else {
// Everything's Ok, display everything wanted
@jungchris
jungchris / ConferenceModel.m
Created August 20, 2015 12:55
indexOfIdInOrganzationsArray
// used to determine correct location of object in array
- (NSInteger)indexOfIdInSessionsArray:(NSNumber*)inputNum {
// simple loop. Could use containsObject instead
for (NSInteger i = 0; i < [self.sessionsArray count]; i++) {
// check for NSNumber object equality
SessionsModel *session = self.sessionsArray[i];
if ([session.sessionId isEqual:inputNum]) {
return i;
}
}
@jungchris
jungchris / CCJNotificationEngine.m
Created August 20, 2015 18:29
Capitalizing Notification Name
NSString *notificationName = [CCJNotificationEngine notificationTargetRandomizer];
NSString *notificationTitle;
if (notificationName) {
if (notificationName.length > 1) {
// NSString *uppercaseFirstLetter = [notificationName stringByReplacingCharactersInRange:NSMakeRange(0,1)
// withString:[[notificationName substringToIndex:1] capitalizedString]];
// notificationTitle = [@"View" stringByAppendingString:uppercaseFirstLetter];
notificationTitle = [self notificationTitleUsingNotificationName:notificationName];
@jungchris
jungchris / CCJNotificationEngine.m
Last active August 29, 2015 14:27
Set Repeating Notifications
+ (void)addLocalNotificationWithRepeatCount:(NSUInteger)repeatCountDesired startOffset:(NSUInteger)daysOffset {
// ask for permission if necessary
[CCJNotificationEngine requestPermissionToSetNotifications];
// NSLog(@"notifications %@", [UIApplication sharedApplication].scheduledLocalNotifications );
// let's set the time to 9:00 am
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy"];
@jungchris
jungchris / TracksTableViewController.m
Last active September 17, 2015 17:37
Filter Method For Tracks
// NOTES: sessionType property from JSON file 'sessions.json' compared to 'tracksString' from 'tracks.json'
//
//
@property (nonatomic, strong) NSString *selectedTrack;
@property (nonatomic, strong) NSArray *filteredArray;
@property (nonatomic, strong) NSArray *sortedArray;
@end
@implementation TracksTableVC
@jungchris
jungchris / SessionsTableViewController.m
Last active September 17, 2015 18:16
Sessions Table Filtered both by Date and Track
// this is the .h file
// properties set by previous view controllers DatesTableVC or TracksTableVC
@property (assign, nonatomic) NSInteger selectedRow;
@property (nonatomic, strong) NSDate *selectedDate;
@property (nonatomic, strong) NSString *selectedTrack;
// ---------------------------------------------------------------------------------------------
// this is the .m file
@interface SessionTableVC ()
@jungchris
jungchris / AppDelegate.m
Last active September 29, 2015 19:36
Control Rotation and Allow for Only One View
// this delegate is executed before each rotation. Here we allow only one view to go to landscape
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
// get the array of VCs from the nav controller
UINavigationController *navControl = (UINavigationController*)self.window.rootViewController;
NSArray *controllerArray = navControl.viewControllers;
NSUInteger controllerCount = [controllerArray count];
// safety check, make sure we have at least one view controller on the stack
if (controllerCount > 0) {
@jungchris
jungchris / CCJVideoPlayerVC.m
Last active October 7, 2015 20:47
Video Player View Controller Force Rotate Back to Portrait
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// check if exiting
if (self.isMovingFromParentViewController) {
NSLog(@"isMovingFromParentViewController");
// set public property to indicate this view will not longer be presented
self.isPresented = NO;
// forces a return to portrait orientation
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
@jungchris
jungchris / CCJTextEngine.m
Created October 23, 2015 15:40
Converting ISO8601 date-times to NSDate and vice-versa
#pragma mark - ISO8601 to NSDate & vice-versa
// Convert ISO 8601 standard Zulu date+time to NSDate
+ (NSDate*)convertISO8601ToNSDate:(NSString*)isoString {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
// Always use this locale when parsing fixed format date strings
NSLocale *posix = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
[formatter setLocale:posix];
@jungchris
jungchris / CCJFileEngine.m
Created November 10, 2015 19:47
Code snippet to save array data using NSKeyedArchiver
// save array data
- (void)saveArrayData {
NSMutableDictionary *dataDict = [[NSMutableDictionary alloc] initWithCapacity:365];
if (urgeArray != nil) {
[dataDict setObject:urgeArray forKey:@"events"]; // save the urges array
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];