Skip to content

Latest commit

 

History

History
161 lines (110 loc) · 2.9 KB

Variables.md

File metadata and controls

161 lines (110 loc) · 2.9 KB

#Variables

###Constants

#define WEATHER_API_URL @"http://warm-wildwood-5296.herokuapp.com/"
NSLog(@"%@", WEATHER_API_URL);

###String

NSString *firstName = @"Scott";
NSString *lastName = @"Doxey";
NSString *fullname = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
NSLog(@"%@", fullname);

###Number

NSNumber *age = @29;
NSLog(@"%@", age);

###Unsigned Integer

NSUInteger age = [@29 unsignedIntegerValue];
NSLog(@"%lu", (unsigned long)age);

###Array

NSArray *apps = @[@"Pages", @"Numbers", @"Keynote"];
NSLog(@"%@", apps);

###Dictionary

NSDictionary *user = @{@"First Name": @"Scott", @"Last Name": @"Doxey"};
NSLog(@"%@", user);

###Log Object Type

NSDictionary *user = @{@"First Name": @"Scott", @"Last Name": @"Doxey"};
NSLog(@"%@", [user class]);

###Log NSDictionary Keys

NSDictionary *user = @{@"First Name": @"Scott", @"Last Name": @"Doxey"};
NSLog(@"%@", [user allKeys]);

###Log NSDictionary Values

NSDictionary *user = @{@"First Name": @"Scott", @"Last Name": @"Doxey"};
NSLog(@"%@", [user allValues]);

###URL

// ViewController.m

@interface ViewController ()
{
    NSMutableData *responseData;
}
@end

@implementation ViewController

- (void)viewDidLoad
{

    NSURL *weatherAPIURL = [NSURL URLWithString:@"http://warm-wildwood-5296.herokuapp.com/"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:weatherAPIURL];

    [[NSURLConnection alloc] initWithRequest:request delegate:self];

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{

    responseData = [[NSMutableData alloc] init];

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{

    [responseData appendData:data];

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{

    NSError *error;

    NSDictionary *cities = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];

    for (NSDictionary *city in cities) {

        NSLog(@"%@", city);

    }

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

}

@end

###ENUM

typedef NS_ENUM(NSInteger, DayOfWeek) {
    DayOfWeekMonday = 1,
    DayOfWeekTuesday = 2,
    DayOfWeekWednesday = 3,
    DayOfWeekThursday = 4,
    DayOfWeekFriday = 5,
    DayOfWeekSaturday = 6,
    DayOfWeekSunday = 7
};

NSLog(@"%ld", (long)DayOfWeekMonday);

###Empty Variables

NSString *emptyString = [NSString string];
NSArray *emptyArray = [NSArray array];
NSDictionary *emptyDict = [NSDictionary dictionary];

###Copying Variables

NSString *firstName = @"Scott";

NSString *otherString = [NSString stringWithString:firstName];
NSString *copy = [[NSString alloc] initWithString:otherString];

NSLog(@"%@", otherString);
NSLog(@"%@", copy);