This repository has been archived by the owner. It is now read-only.

Class method +configuration not allowed in Swift #568

Closed
jonastreub opened this Issue Jan 26, 2015 · 7 comments

Comments

Projects
None yet
3 participants
@jonastreub

jonastreub commented Jan 26, 2015

When using Mapbox in a Swift project, it's impossible to use [RMConfiguration configuration], since Swift does not generate an appropriate method for this (see also this SO answer).

Giving it a slightly different method name would work.

@JohnRbk

This comment has been minimized.

JohnRbk commented Jan 26, 2015

Same issue here. If you want a short-term workaround, here is what I did:

I created an RMConfiguration category (something like RMConfiguration+Workaround.m and RMConfiguration+Workaround.h) in Objective-C. Within the category definition, implement an alias for the configuration class-member method using some other name. After including the category in your bridging header, you can easily call the alias in Swift.

@incanus

This comment has been minimized.

Contributor

incanus commented Jan 26, 2015

Oh, interesting. Thanks for this flag @jonastreub. This comes from the upstream project, and though I haven't typically liked to diverge in past for little things, this makes sense now because:

  1. This is an oddly-named singleton.
  2. Upstream is no longer an active project.

I'll get a fix in for this.

@incanus

This comment has been minimized.

Contributor

incanus commented Jan 26, 2015

Ok, give the above branch a try and see how it works for you @jonastreub @JohnRbk? This seems to be a Swift compiler hinting issue as structurally, this is the same — I just called it sharedInstance now.

RMConfiguration.sharedInstance().accessToken = "pk......"
@incanus

This comment has been minimized.

Contributor

incanus commented Jan 26, 2015

More on this:

http://stackoverflow.com/questions/24148464/how-to-call-an-objective-c-singleton-from-swift

A followup: because class methods like +[XYZThing thing] are treated like initializers by the ObjC to Swift translator (even if that doesn't seem to fully work right now), that naming pattern is a bad idea for singletons.

@JohnRbk

This comment has been minimized.

JohnRbk commented Jan 27, 2015

I ran a quick test and it seems like your update works. Without any call to set the accessToken, running a proxy shows my app making requests to https://api.tiles.mapbox.com/v3/...

I added the following line:

RMConfiguration.sharedInstance().accessToken = "<<API KEY>>"

...and I can see API calls to https://api.tiles.mapbox.com/v4/...

Seems like it works fine.

Thanks for the fix.

@jonastreub

This comment has been minimized.

jonastreub commented Jan 27, 2015

@incanus Thanks for the quick fix!

@incanus

This comment has been minimized.

Contributor

incanus commented Jan 27, 2015

Ok, merged into develop and will make it into the next release!

@incanus incanus closed this Jan 27, 2015

earltedly referenced this issue in activeintime/mapbox-ios-sdk Mar 31, 2015

Merge tag '1.6.0' into release
* tag '1.6.0': (41 commits)
  bump podspec for 1.6.0
  update changelog for 1.6.0
  fixes #566: remove v3 API access
  fixes #407: GRMustache 6.8.3 -> 7.3.0
  log warning on failed Mapbox source & no access token set
  remove some unneeded log verbosity
  Mapbox -> Mapbox iOS SDK
  Markdown link syntax improvements for appledoc parsing
  bump podspec
  update changelog for 1.5.1
  refs #568: attempt to hint to Swift compiler about singleton constructor
  stronger wording on tokens
  updates to contrib notes
  fix docs cleanup
  bump CocoaPods version
  README tweaks
  update changelog for 1.5.0
  Fix typo in cache_size PRAGMA
  Use localized NSLocationWhenInUseUsageDescription key for assert.
  update support email
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.