Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Restaurant Reviews App Adding Reviews and a Map Creating Restaurant Pins

McIvor Steiner
McIvor Steiner
9,971 Points

How to just pass the businesses to the 'addAnnotations' method?

In this video, you ran into an issue where it was not working if you just passed the businesses to the addAnnotations method on the map. The business object does conform to the MKAnnotation protocol, so this should work, and would be a lot simpler than the solution that was used in the video. Has anyone determined how to make the first approach work?

Angus Muller
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Angus Muller
iOS Development Techdegree Graduate 12,473 Points

For me it worked straight away with the first way of doing it (addAnnotation method) without having to implerment the second way that was shown , I don't know why it worked for me though?

2 Answers

Sarah Hurtgen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Sarah Hurtgen
Treehouse Project Reviewer

In the video he accidentally typed longitude instead of latitude in the YelpBusiness extension, if you follow exactly what he typed, it won't work - but if you follow what he says, it should work fine!

// his original line
    var coordinate: CLLocationCoordinate2D {
        return CLLocationCoordinate2D(latitude: location.longitude, longitude: location.longitude)
    }
// how it should read
    var coordinate: CLLocationCoordinate2D {
        return CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude)
    }
Nathan F.
Nathan F.
30,773 Points

I wondered what his error was because it worked perfectly fine for me. That makes sense! Haha

Don't make the same mistake as I did when adding the annotations.

Apple as 2 methods defined. One has an "s" (annotations) accept an array of MKAnnotations And the other is not an arrays

open func addAnnotation(_ annotation: MKAnnotation)

open func addAnnotations(_ annotations: [MKAnnotation])