Skip to content

Instantly share code, notes, and snippets.

View jen2's full-sized avatar

Jen Sipila jen2

  • New York, New York
View GitHub Profile
@jen2
jen2 / Dinner.h
Created May 6, 2017 14:04
Code for Dinner class in "An Introduction to Categories in Objective-C."
//Dinner.h
#import <Foundation/Foundation.h>
@interface Dinner: NSObject
@property (nonatomic, strong) NSString *appetizer;
@property (nonatomic, strong) NSString *mainDish;
@property (nonatomic, strong) NSString *dessert;
@property (nonatomic, strong) NSArray *ingredientsForAppetizer;
@property (nonatomic, strong) NSArray *ingredientsForMainDish;
@jen2
jen2 / Dinner.m
Created May 6, 2017 14:06
Dinner.m file for "An Introduction to Categories in Objective-C."
// Dinner.m
#import "Dinner.h"
@implementation Dinner
- (void)prepareAppetizer
{
//Do something to prepare the appetizer.
}
- (void)cookMainDish {
//Do something to cook the main dish.
@jen2
jen2 / Dinner+CleanUp.h
Created May 6, 2017 14:09
Category Files Dinner+CleanUp.h & Dinner+CleanUp.m for "An Introduction to Categories in Objective-C."
// Dinner+CleanUp.h
#import "Dinner.h"
@interface Dinner (CleanUp)
- (void)bringDishesToSink;
- (NSUInteger)countTotalDishes;
- (void)putDishesInDishwasher;
- (void)removeDishesFromDishwasher;
@end
@jen2
jen2 / ViewController.m
Last active May 7, 2017 14:15
Initial ViewController.m Set Up for "Build a World Clock in Objective-C."
//ViewController.m
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *NYC;
@property (weak, nonatomic) IBOutlet UIButton *paris;
@property (weak, nonatomic) IBOutlet UIButton *moscow;
@property (weak, nonatomic) IBOutlet UIButton *hongKong;
@property (weak, nonatomic) IBOutlet UIButton *honolulu;
@jen2
jen2 / ViewController.m
Last active May 7, 2017 20:13
Setting up implementation for cityButtonTapped: method in "Build a World Clock in Objective-C."
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)cityButtonTapped:(UIButton *)sender { //Gets which button is tapped
switch (sender.tag) {
case 100:
self.timeZone = @"EST";
self.selectedButton = self.nyc;
@jen2
jen2 / ViewController.m
Last active May 7, 2017 14:57
Implementation for setTappedCityTimer: andButton: method in "Build a World Clock in Objective-C."
-(void)setTappedCityTimer {
[self.timer invalidate];
self.timer = nil;
[self setDateTimeLabelsWithTimeZone];
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(setDateTimeLabelsWithTimeZone) userInfo:nil repeats:YES];
}
@jen2
jen2 / ViewController.m
Last active May 7, 2017 16:11
Date and time formatting with the formatCurrentDateTimeForTimeZone method for "Build a World Clock in Objective-C."
-(NSArray *)formatCurrentDateTimeForTimeZone { //Gets current date each time it's fired.
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
NSLocale *posix = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
NSTimeZone *localTimeZone = [NSTimeZone timeZoneWithAbbreviation:self.timeZone];
[dateFormatter setLocale:posix];
[dateFormatter setDateFormat:@"EEEE MMMM dd y"];
[dateFormatter setTimeZone:localTimeZone];
[timeFormatter setLocale:posix];
[timeFormatter setDateFormat:@"h:mm:ss a"];
@jen2
jen2 / ViewController.m
Created May 7, 2017 17:11
Code completed before highlighting selected button for "Build a World Clock in Objective-C."
@interface ViewController ()
@property (nonatomic, weak) IBOutlet UIButton *nyc;
@property (nonatomic, weak) IBOutlet UIButton *paris;
@property (nonatomic, weak) IBOutlet UIButton *moscow;
@property (nonatomic, weak) IBOutlet UIButton *hongKong;
@property (nonatomic, weak) IBOutlet UIButton *honolulu;
@property (nonatomic, weak) IBOutlet UIButton *seattle;
@property (nonatomic, weak) IBOutlet UILabel *timeLabel;
@property (nonatomic, weak) IBOutlet UILabel *dateLabel;
@jen2
jen2 / ViewController.m
Last active May 7, 2017 19:57
Show the unhighlightDeselected method for "Build a World Clock in Objective-C."
-(void)unhighlightDeselected {
NSArray *cities = [@[self.nyc, self.paris, self.moscow, self.hongKong, self.honolulu, self.seattle]mutableCopy];
NSMutableArray *unselectedCities = [NSMutableArray array];
for (UIButton *city in cities) {
if (city != self.selectedButton) {
[unselectedCities addObject:city];
}
}
[unselectedCities setValue:[UIColor blueColor] forKey:@"tintColor"];
@jen2
jen2 / ViewController.m
Created May 7, 2017 20:05
Complete ViewController.m file for "Build a World Clock in Objective-C."
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, weak) IBOutlet UIButton *nyc;
@property (nonatomic, weak) IBOutlet UIButton *paris;
@property (nonatomic, weak) IBOutlet UIButton *moscow;
@property (nonatomic, weak) IBOutlet UIButton *hongKong;
@property (nonatomic, weak) IBOutlet UIButton *honolulu;
@property (nonatomic, weak) IBOutlet UIButton *seattle;