Giter Club home page Giter Club logo

locationtrivia-dictionaries-001-prework-ios's Introduction

Location Trivia

Objectives

  1. Apply what you've learned about collections to correctly store some real-world information.
  2. Verify that a dictionary contains the expected keys.
  3. Retrieve a stored dictionary by the value for a key.

Introduction

We're going to work towards building an app to allow users to share trivia facts about locations around the city. As users walk around, they can be notified of nearby trivia items. Before we get to work with trivia, we need to handle the data about nearby locations.

In this exercise, we're going to start by handling some data about a few locations in New York City. We're going to save the location's name, latitude, and longitude as values in a dictionary. In Objective-C, a manual declaration of such a dictionary would look like this:

NSDictionary *flatironSchool = @{ @"name": @"The Flatiron School",
                                  @"latitude": @34.432,
                                  @"longitude": @-23.67 };

Instructions

Navigate to the FISAppDelegate.h header file and declare the following methods. Set them to return nil in the FISAppDelegate.m implementation file. Run the tests to see that most of them fail.

  • stringByTruncatingNameOfLocation:toLength: that takes two arguments, an NSDictionary called location and an NSUInteger called length; and returns an NSString.

  • dictionaryForLocationWithName:latitude:longitude: that takes three arguments, an NSString called name, and two CGFloats called latitude and longitude; and returns an NSDictionary.

  • namesOfLocations: that takes one NSArray argument called locations and returns an NSArray.

  • dictionaryIsValidLocation: that takes one NSDictionary argument and returns a BOOL.

  • locationNamed:inLocations: that takes two arguments, an NSString called name and an NSArray called locations; and returns an NSDictionary.

Now, write out the method bodies for each method one by one. Run the tests each time you finish a method to check your work. Reference each of the tests to know what they're expecting.

  1. stringByTruncatingNameOfLocation:toLength: should return a string containing the beginning of the submitted location's name with the number of letters specified in the length argument.
    Hint: Look up the substringToIndex: method on NSString.

  2. dictionaryForLocationWithName:latitude:longitude: should return a dictionary containing the three argument values stored to keys of the argument names (@"name", @"latitude", @"longitude").

  3. namesOfLocations: should return an array containing all of the values for the name key in the location dictionaries in the submitted locations array.

  4. dictionaryIsValidLocation: should return YES only if the submitted location dictionary has exactly three keys by the names of @"name", @"latitude", and @"longitude". If any of these conditions fail, the method should return NO.
    Advanced: Write additional checks to determine that the value for latitude falls between -90.0 and 90.0, that the value for longitude falls between 180.0 and -180.0, and that the value for name is not an empty string. However, there are no tests for these cases.

  5. locationNamed:inLocations: should return the location dictionary in the submitted locations array with the matching value for the name key as the submitted name string. If there are no matches, then it should return nil.

locationtrivia-dictionaries-001-prework-ios's People

Contributors

zdrossman avatar markedwardmurray avatar fs-lms-test-bot avatar chrisgonzgonz avatar misterfifths avatar hdinhof1 avatar jmburges avatar sarogers avatar fislabstest avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.