tags | languages |
---|---|
objects, collections |
swift |
#Location Trivia Objects
An app to share the different trivia items of life around you. As users walk around NYC they are notified of nearby trivia items. Users are also able to add trivia facts and tag them to any location nearby. Through this app, we can all be a little bit smarter.
Before getting started - key thing - for this lab, you do not need to know / use / understand optionals. If you get messages suggesting you need to add a ?
or !
to your code though, you do need to know that the compiler / linter thinks you are trying to assign a variable to nil. For this lab, we will not allow any of our objects to ever be nil! (Either initialize a variable when declared or in an initializer.)
- First create a new
FISLocation
class, add in the following properties:
let name : String
var latitude : Double
var longitude : Double
-
Create an initializer that takes in the three properties and assigns them correctly.
-
Create a
shortenLocationName
method in yourFISLocation
class. -
Create a
getLocationNamesWithLocations
method that takes an Array ofFISLocation
objects and just return their names. This should be a class function. -
Create a
verifyLocation
method to be an instance method forFISLocation
that ensures the location name is not blank (i.e.""
), and the location latitude and longitude are both possible (remember there are limits on the range of latitude and longitude!) -
Create a
searchForLocationName:inLocations:
method to search an Array ofFISLocation
objects. -
Create a new class called
FISTrivia
. This class should have the following properties:var content : String var likes : Int
-
Create an initializer for
FISTrivia
that takes an argument for all of the properties and sets them appropriately -
Add an
Array
property toFISLocation
to hold trivia items -
Write a method called
topTrivia
that returns the trivia item with the most likes.Assume this method will always return something, even if there are no trivia items for a location. (i.e. a placeholder trivia with placeholder content and zero likes.)
##Hints
There are some global functions in swift that may be helpful to creating these classes. These are:
advance()
countElements()
Additionally, strings work differently in Swift than they do in Objective-C. Consider doing some reading so you understand how they are constructed.