Skip to content
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

Wrap Search Configs #238

Merged
merged 8 commits into from Mar 24, 2017
Merged

Wrap Search Configs #238

merged 8 commits into from Mar 24, 2017

Conversation

sarahsnow1
Copy link
Member

Overview

This adds objective-c support for part of the Pelias API. A follow-up PR will integrate these changes into a new MapzenSearch object and complete objective-c compatibility.

Proposed Changes

  • Wrap Pelias structs in NSObject equivalents
  • Wrap and unwrap these objects using MapzenSearchDataConverter

Future work:

Closes #80

@sarahsnow1 sarahsnow1 changed the title 80 wrap configs Wrap Search Configs Mar 22, 2017
import Foundation
import Pelias

public class MapzenResponse : NSObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be something more descriptive like SearchResponse.

Also it's not practice in swift to prefix names with things like MZ or Mapzen because namespaces are implicit. So if there's a namespace conflict you would use ModuleName.Class.Function() instead of Class.Function(). So in general I would remove that prefix from these classes / structs / etc. This is something I failed to understand while building Pelias, so lets fix that here :)

There are always exceptions however. For example the MapzenManager is a good one since it's a state manager for Mapzen services, but otherwise I think we can be a little more loose with naming.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While writing my swift code I had objective-c's lack of namespaces in mind (eek!). I think you're right, this can be more descriptive, I'll change it to SearchResponse. I also agree re exceptions like MapzenManager.

...combining parts of what we are both thinking, how do you feel about adding an MZ prefix for the objective-c class names? So something like this:

@objc(MZSearchResponse)
public class SearchResponse: NSObject

import Foundation
import Pelias

public class MapzenPlaceConfig : NSObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are you thoughts on moving all of these into a single swift file? It's common practice to have common structs / class grouped in the same file in Swift.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its against what inherently feels natural to me (its overwhelming to see large files) but if its swift common practice I'll move it into one file.

@@ -0,0 +1,153 @@
//
// MapzenSearchDataConverter.swift
// Pods
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Just noticed the Pods name here. This should be the project name, so Mapzen-ios-sdk or something similar.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update to ios-sdk

import Foundation
import Pelias

public class MzSearchRect: NSObject {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah like I said above we can probably remove all of the prefixes here and then for things like SearchBoundaryCircle which will conflict on the namespace you should be able to reference it by module name like Pelias.SearchBoundaryCircle

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about changing the sdk module name from ios_sdk to Mapzen?

let center = MzGeoPoint(latitude: 70.0, longitude: 40.0)
let searchCircle = MzSearchCircle(center: center, radius: 8)
let circle = SearchBoundaryCircle(center: MapzenSearchDataConverter.unwrapPoint(center), radius: 8)
XCTAssertEqual(searchCircle.circle, circle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably use XCTAssertEqualWithAccuracy() here and for the accuracy part use DBL_EPSILON to avoid possible compiler weirdness with floats, since checking equality with floats tends to be hit-or-miss.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that weirdness was just when the float was returned from TGMapViewController's getPosition?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but in general you shouldn't do direct equality checks on floats without an accuracy check in place (which is why I started down that path in the first place).

XCTAssertEqual(wrapped.dataSource, .openStreetMap)
XCTAssertEqual(wrapped.layer, .venue)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: whitespace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing whitespace on this line:
screen shot 2017-03-23 at 2 16 19 pm

Was it on a different line?

@msmollin msmollin merged commit 05a3546 into master Mar 24, 2017
@msmollin msmollin deleted the 80-wrap-configs branch March 24, 2017 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants