Skip to content

assessment part one #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions FixaDaApp/FixaDaApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
4D31B3791C792A6700171150 /* VenueObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D31B3781C792A6700171150 /* VenueObject.m */; };
79510F25E25C142657CE2DC4 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5C1C5BEFC8D1D1F43B84295A /* libPods.a */; };
8D4F05B61C710A8E003B3131 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D4F05B51C710A8E003B3131 /* main.m */; };
8D4F05B91C710A8E003B3131 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D4F05B81C710A8E003B3131 /* AppDelegate.m */; };
Expand All @@ -20,6 +21,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
4D31B3771C792A6700171150 /* VenueObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VenueObject.h; sourceTree = "<group>"; };
4D31B3781C792A6700171150 /* VenueObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VenueObject.m; sourceTree = "<group>"; };
51DA72322BD0057FB2DF45ED /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
5C1C5BEFC8D1D1F43B84295A /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
8D4F05B11C710A8E003B3131 /* FixaDaApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FixaDaApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -91,6 +94,8 @@
8D4F05BB1C710A8E003B3131 /* ViewController.m */,
8DB9ED8E1C722B12003A03E0 /* FoursquareAPIManager.h */,
8DB9ED8F1C722B13003A03E0 /* FoursquareAPIManager.m */,
4D31B3771C792A6700171150 /* VenueObject.h */,
4D31B3781C792A6700171150 /* VenueObject.m */,
8D4F05BD1C710A8E003B3131 /* Main.storyboard */,
8D4F05C01C710A8E003B3131 /* Assets.xcassets */,
8D4F05C21C710A8E003B3131 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -241,6 +246,7 @@
8D4F05B91C710A8E003B3131 /* AppDelegate.m in Sources */,
8D4F05B61C710A8E003B3131 /* main.m in Sources */,
8DB9ED901C722B13003A03E0 /* FoursquareAPIManager.m in Sources */,
4D31B3791C792A6700171150 /* VenueObject.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 4 additions & 4 deletions FixaDaApp/FixaDaApp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<mapView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" mapType="standard" showsUserLocation="YES" translatesAutoresizingMaskIntoConstraints="NO" id="QhC-Y4-i8h">
<rect key="frame" x="0.0" y="0.0" width="600" height="100"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="225.5"/>
</mapView>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="BMq-V3-f2f">
<rect key="frame" x="0.0" y="100" width="600" height="500"/>
<rect key="frame" x="0.0" y="225" width="600" height="374.5"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" textLabel="4Wd-lS-p0j" style="IBUITableViewCellStyleDefault" id="5cm-8d-a5a">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="BeepBoopCellIdentifier" textLabel="4Wd-lS-p0j" style="IBUITableViewCellStyleDefault" id="5cm-8d-a5a">
<rect key="frame" x="0.0" y="28" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="5cm-8d-a5a" id="cpW-0e-B2H">
Expand All @@ -48,7 +48,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="BMq-V3-f2f" firstAttribute="top" secondItem="QhC-Y4-i8h" secondAttribute="bottom" id="829-uy-XA8"/>
<constraint firstItem="QhC-Y4-i8h" firstAttribute="height" secondItem="BMq-V3-f2f" secondAttribute="height" multiplier="0.2" id="DcL-ga-xdl"/>
<constraint firstItem="QhC-Y4-i8h" firstAttribute="height" secondItem="BMq-V3-f2f" secondAttribute="height" multiplier="0.6" id="DcL-ga-xdl"/>
<constraint firstAttribute="trailing" secondItem="BMq-V3-f2f" secondAttribute="trailing" id="Ddx-sp-gAW"/>
<constraint firstItem="BMq-V3-f2f" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="PGd-F5-XwA"/>
<constraint firstItem="QhC-Y4-i8h" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="PS4-bX-CJK"/>
Expand Down
2 changes: 1 addition & 1 deletion FixaDaApp/FixaDaApp/FoursquareAPIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

+ (void)findSomething:(NSString *)query
atLocation:(CLLocation *)location
completion:(void(^)(NSArray *data))completion;
completion:(void(^)(NSMutableArray *data))completion;

@end
49 changes: 40 additions & 9 deletions FixaDaApp/FixaDaApp/FoursquareAPIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@

#import "FoursquareAPIManager.h"
#import <AFNetworking/AFNetworking.h>
#import "VenueObject.h"

#define kFoursquareAPIClientID @"GWKJBVWFYBJQ02T3TRBB4VBL24AIO4TCMJCGIQ5ADKVKJXGP"
#define kFoursquareAPIClientSecret @"2WMEZCDQNKNB5XAE5F4BY1VHBK1HITYRU1JEVCOAD2QRLXDJ"

@interface FoursquareAPIManager ()

@end

@implementation FoursquareAPIManager

/**
Expand All @@ -23,12 +28,14 @@ @implementation FoursquareAPIManager
&ll=40.7,-74
&query=sushi

**/
**/

+ (void)findSomething:(NSString *)query
atLocation:(CLLocation *)location
completion:(void(^)(NSArray *data))completion
completion:(void(^)(NSMutableArray *data))completion
{
NSMutableArray *locations = [[NSMutableArray alloc] init]; // alloc init array

NSString *baseURL = @"https://api.foursquare.com/v2/venues/search";
NSString *url = [NSString stringWithFormat:@"%@?client_id=%@&client_secret=%@&v=20160215&ll=%f,%f&query=%@", baseURL, kFoursquareAPIClientID, kFoursquareAPIClientSecret, location.coordinate.latitude, location.coordinate.longitude, query];

Expand All @@ -38,13 +45,37 @@ + (void)findSomething:(NSString *)query
parameters:nil
progress:nil
success:^(NSURLSessionTask *task, id responseObject)
{

} failure:^(NSURLSessionTask *operation, NSError *error)
{
NSLog(@"Error: %@", error);
}];

{

if (responseObject != nil) {

NSArray *venuesMy = [[responseObject objectForKey:@"response"] objectForKey:@"venues"];

for (NSDictionary *venue in venuesMy) {

NSString *venueName = [venue objectForKey:@"name"]; // pull info from dictionary
NSString *lat = [[venue objectForKey:@"location"]objectForKey:@"lat"];
NSString *lng = [[venue objectForKey:@"location"]objectForKey:@"lng"];

double latDbl = lat.doubleValue; // convert to doubles
double lngDbl = lng.doubleValue;

VenueObject *venue = [[VenueObject alloc] init]; // initialize storage object

venue.name = venueName; // save in object
venue.lat = latDbl;
venue.lng = lngDbl;

[locations addObject:venue]; // add to object
}
completion(locations);
}

} failure:^(NSURLSessionTask *operation, NSError *error)
{
NSLog(@"Error: %@", error);
}];

}

@end
2 changes: 1 addition & 1 deletion FixaDaApp/FixaDaApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Show you the places!</string>
<string>Hi, please accept so that we can show you the places!</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand Down
17 changes: 17 additions & 0 deletions FixaDaApp/FixaDaApp/VenueObject.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// VenueObject.h
// FixaDaApp
//
// Created by Shena Yoshida on 2/20/16.
// Copyright © 2016 Michael Kavouras. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface VenueObject : NSObject

@property (nonatomic) NSString *name;
@property (nonatomic) double lat;
@property (nonatomic) double lng;

@end
13 changes: 13 additions & 0 deletions FixaDaApp/FixaDaApp/VenueObject.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// VenueObject.m
// FixaDaApp
//
// Created by Shena Yoshida on 2/20/16.
// Copyright © 2016 Michael Kavouras. All rights reserved.
//

#import "VenueObject.h"

@implementation VenueObject

@end
33 changes: 20 additions & 13 deletions FixaDaApp/FixaDaApp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

#import "ViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import "FoursquareAPIManager.h"
#import "VenueObject.h"

@interface ViewController ()
<
Expand All @@ -19,12 +21,10 @@ @interface ViewController ()

@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic) CLLocationManager *locationManager;

@property (nonatomic, assign) BOOL foundPlaces;

@property (nonatomic) NSArray *venues;
@property (nonatomic) NSMutableArray *venues;

@end

Expand All @@ -33,17 +33,21 @@ @implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];

self.mapView.showsUserLocation = YES;
self.locationManager = [[CLLocationManager alloc] init];

self.tableView.delegate = self;
self.tableView.dataSource = self;

self.mapView.delegate = self;

self.locationManager = [[CLLocationManager alloc] init];
self.venues = [[NSMutableArray alloc] init];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.locationManager requestWhenInUseAuthorization];
}


Expand All @@ -56,15 +60,15 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 0;
return self.venues.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BeepBoopCellIdentifier"];
NSDictionary *venue = self.venues[indexPath.row];
NSString *name = venue[@"name"];

VenueObject *venue = self.venues[indexPath.row];
NSString *name = venue.name; // this comes from the api call and object...
cell.textLabel.text = name;

return cell;
Expand Down Expand Up @@ -96,7 +100,9 @@ - (void)fetchVenuesAtLocation:(CLLocation *)location
__weak typeof(self) weakSelf = self;
[FoursquareAPIManager findSomething:@"music"
atLocation:location
completion:^(NSArray *data){
completion:^(NSMutableArray *data){

self.venues = data; // pull data with the block!

weakSelf.venues = data;
[weakSelf.tableView reloadData];
Expand All @@ -109,14 +115,15 @@ - (void)showPins
{
[self.mapView removeAnnotations:self.mapView.annotations];

for (NSDictionary *venue in self.venues) {
double lat = [venue[@"location"][@"lat"] doubleValue];
double lng = [venue[@"location"][@"lng"] doubleValue];
for (VenueObject *venue in self.venues) {
double lat = venue.lat;
double lng = venue.lng;

MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = CLLocationCoordinate2DMake(lat, lng);
[self.mapView addAnnotation:point];
}
}


@end