Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[ios, macos] Convert various class methods to class properties #11674

Merged
merged 1 commit into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions platform/darwin/src/MGLAccountManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
NS_ASSUME_NONNULL_BEGIN

/**
The MGLAccountManager object provides a global way to set a Mapbox API access
The `MGLAccountManager` object provides a global way to set a Mapbox API access
token.
*/
MGL_EXPORT
Expand All @@ -14,9 +14,9 @@ MGL_EXPORT
#pragma mark Authorizing Access

/**
Set the
The
<a href="https://www.mapbox.com/help/define-access-token/">Mapbox access token</a>
to be used by all instances of MGLMapView in the current application.
used by all instances of `MGLMapView` in the current application.

Mapbox-hosted vector tiles and styles require an API access token, which you
can obtain from the
Expand All @@ -25,24 +25,16 @@ MGL_EXPORT
your Mapbox account. They also deter other developers from using your styles
without your permission.

@param accessToken A Mapbox access token. Calling this method with a value of
`nil` has no effect.
Setting this property to a value of `nil` has no effect.

@note You must set the access token before attempting to load any Mapbox-hosted
style. Therefore, you should generally set it before creating an instance of
MGLMapView. The recommended way to set an access token is to add an entry to
your application’s Info.plist file with the key `MGLMapboxAccessToken` and
the type String. Alternatively, you may call this method from your
`MGLMapView`. The recommended way to set an access token is to add an entry
to your application’s Info.plist file with the key `MGLMapboxAccessToken`
and the type `String`. Alternatively, you may call this method from your
application delegate’s `-applicationDidFinishLaunching:` method.
*/
+ (void)setAccessToken:(nullable NSString *)accessToken;

/**
Returns the
<a href="https://www.mapbox.com/help/define-access-token/">Mapbox access token</a>
in use by instances of MGLMapView in the current application.
*/
+ (nullable NSString *)accessToken;
@property (class, nullable) NSString *accessToken;

+ (BOOL)mapboxMetricsEnabledSettingShownInApp __attribute__((unavailable("Telemetry settings are now always shown in the ℹ️ menu.")));

Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MGLAccountManager_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@interface MGLAccountManager (Private)

/// Returns the shared instance of the `MGLAccountManager` class.
+ (instancetype)sharedManager;
@property (class, nonatomic, readonly) MGLAccountManager *sharedManager;
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of nonatomic for these class properties is consistent with previous behavior when these properties were class methods. atomic is a remnant of cargo-cult programming that resulted in excessive locking and dispatching early on.


/// The current global access token.
@property (atomic) NSString *accessToken;
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MGLMapSnapshotter.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ typedef void (^MGLMapSnapshotCompletionHandler)(MGLMapSnapshot* _Nullable snapsh
```swift
let camera = MGLMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 37.7184, longitude: -122.4365), fromDistance: 100, pitch: 20, heading: 0)

let options = MGLMapSnapshotOptions(styleURL: MGLStyle.satelliteStreetsStyleURL(), camera: camera, size: CGSize(width: 320, height: 480))
let options = MGLMapSnapshotOptions(styleURL: MGLStyle.satelliteStreetsStyleURL, camera: camera, size: CGSize(width: 320, height: 480))
options.zoomLevel = 10

let snapshotter = MGLMapSnapshotter(options: options)
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MGLNetworkConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface MGLNetworkConfiguration : NSObject

/// Returns the shared instance of the `MGLNetworkConfiguration` class.
+ (instancetype)sharedManager;
@property (class, nonatomic, readonly) MGLNetworkConfiguration *sharedManager;

/// The current API base URL. If `nil`, the Mapbox default base API URL is in use.
@property (atomic, nullable) NSURL *apiBaseURL;
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MGLOfflineStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ MGL_EXPORT
/**
Returns the shared offline storage object.
*/
+ (instancetype)sharedOfflineStorage;
@property (class, nonatomic, readonly) MGLOfflineStorage *sharedOfflineStorage;

#pragma mark - Accessing the Delegate

Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MGLRasterTileSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern MGL_EXPORT const MGLTileSourceOption MGLTileSourceOptionTileSize;
.maximumZoomLevel: 16,
.tileSize: 512,
.attributionInfos: [
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com"))
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com"))
]
])
mapView.style?.addSource(source)
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MGLRendererConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface MGLRendererConfiguration : NSObject

/** Returns an instance of the current renderer configuration. */
+ (instancetype)currentConfiguration;
@property (class, nonatomic, readonly) MGLRendererConfiguration *currentConfiguration;

/** The file source to use. Defaults to `mbgl::DefaultFileSource` */
@property (nonatomic, readonly) mbgl::DefaultFileSource *fileSource;
Expand Down
12 changes: 6 additions & 6 deletions platform/darwin/src/MGLStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ MGL_EXPORT
`-streetsStyleURLWithVersion:` method instead. Such details may change
significantly from version to version.
*/
+ (NSURL *)streetsStyleURL;
@property (class, nonatomic, readonly) NSURL *streetsStyleURL;

/**
Returns the URL to the given version of the
Expand Down Expand Up @@ -98,7 +98,7 @@ MGL_EXPORT
`-outdoorsStyleURLWithVersion:` method instead. Such details may change
significantly from version to version.
*/
+ (NSURL *)outdoorsStyleURL;
@property (class, nonatomic, readonly) NSURL *outdoorsStyleURL;

/**
Returns the URL to the given version of the
Expand All @@ -122,7 +122,7 @@ MGL_EXPORT
`-lightStyleURLWithVersion:` method instead. Such details may change
significantly from version to version.
*/
+ (NSURL *)lightStyleURL;
@property (class, nonatomic, readonly) NSURL *lightStyleURL;

/**
Returns the URL to the given version of the
Expand All @@ -147,7 +147,7 @@ MGL_EXPORT
`-darkStyleURLWithVersion:` method instead. Such details may change
significantly from version to version.
*/
+ (NSURL *)darkStyleURL;
@property (class, nonatomic, readonly) NSURL *darkStyleURL;

/**
Returns the URL to the given version of the
Expand All @@ -172,7 +172,7 @@ MGL_EXPORT
`-satelliteStyleURLWithVersion:` method instead. Such details may change
significantly from version to version.
*/
+ (NSURL *)satelliteStyleURL;
@property (class, nonatomic, readonly) NSURL *satelliteStyleURL;

/**
Returns the URL to the given version of the
Expand Down Expand Up @@ -203,7 +203,7 @@ MGL_EXPORT
`-satelliteStreetsStyleURLWithVersion:` method instead. Such details may
change significantly from version to version.
*/
+ (NSURL *)satelliteStreetsStyleURL;
@property (class, nonatomic, readonly) NSURL *satelliteStreetsStyleURL;

/**
Returns the URL to the given version of the
Expand Down
2 changes: 1 addition & 1 deletion platform/darwin/src/MGLVectorTileSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
.minimumZoomLevel: 9,
.maximumZoomLevel: 16,
.attributionInfos: [
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com"))
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com"))
]
])
mapView.style?.addSource(source)
Expand Down
12 changes: 6 additions & 6 deletions platform/darwin/test/MGLDocumentationExampleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
.maximumZoomLevel: 16,
.tileSize: 512,
.attributionInfos: [
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com"))
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com"))
]
])
mapView.style?.addSource(source)
Expand Down Expand Up @@ -115,7 +115,7 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
.minimumZoomLevel: 9,
.maximumZoomLevel: 16,
.attributionInfos: [
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com"))
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com"))
]
])
mapView.style?.addSource(source)
Expand Down Expand Up @@ -280,7 +280,7 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
.maximumZoomLevel: 16,
.tileSize: 512,
.attributionInfos: [
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com"))
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com"))
]
])
mapView.style?.addSource(source)
Expand All @@ -300,7 +300,7 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
.maximumZoomLevel: 16,
.tileSize: 256,
.attributionInfos: [
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com"))
MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "https://mapbox.com"))
]
])
mapView.style?.addSource(source)
Expand Down Expand Up @@ -370,15 +370,15 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
#endif

class MGLStyle {
static func satelliteStreetsStyleURL() -> URL {
static var satelliteStreetsStyleURL: URL {
return MGLDocumentationExampleTests.styleURL
}
}

//#-example-code
let camera = MGLMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 37.7184, longitude: -122.4365), fromDistance: 100, pitch: 20, heading: 0)

let options = MGLMapSnapshotOptions(styleURL: MGLStyle.satelliteStreetsStyleURL(), camera: camera, size: CGSize(width: 320, height: 480))
let options = MGLMapSnapshotOptions(styleURL: MGLStyle.satelliteStreetsStyleURL, camera: camera, size: CGSize(width: 320, height: 480))
options.zoomLevel = 10

let snapshotter = MGLMapSnapshotter(options: options)
Expand Down
1 change: 1 addition & 0 deletions platform/ios/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The 4.0._x_ series of releases will be the last to support iOS 8. The minimum iO
* Removed support for 32-bit simulators. ([#10962](https://github.com/mapbox/mapbox-gl-native/pull/10962))
* Added Danish and Hebrew localizations. ([#10967](https://github.com/mapbox/mapbox-gl-native/pull/10967), [#11136](https://github.com/mapbox/mapbox-gl-native/pull/11134))
* Removed methods, properties, and constants that had been deprecated as of v3.7.6. ([#11205](https://github.com/mapbox/mapbox-gl-native/pull/11205), [#11681](https://github.com/mapbox/mapbox-gl-native/pull/11681))
* Refined certain Swift interfaces by converting them from class methods to class properties. ([#11674](https://github.com/mapbox/mapbox-gl-native/pull/11674))

### Styles

Expand Down
2 changes: 1 addition & 1 deletion platform/ios/Mapbox.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ panel.addSubview(pitchSwitch)
Put your access token into a plain text file called `token`. Then select the “token” placeholder below, go to Editor ‣ Insert File Literal, and select the `token` file.
*/
var accessToken = try String(contentsOfURL: <#token#>)
MGLAccountManager.setAccessToken(accessToken)
MGLAccountManager.accessToken = accessToken

class PlaygroundAnnotationView: MGLAnnotationView {

Expand Down
2 changes: 1 addition & 1 deletion platform/ios/docs/guides/Info.plist Keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Set the [Mapbox access token](https://www.mapbox.com/help/define-access-token/)

Mapbox-hosted vector tiles and styles require an API access token, which you can obtain from the [Mapbox account page](https://www.mapbox.com/studio/account/tokens/). Access tokens associate requests to Mapbox’s vector tile and style APIs with your Mapbox account. They also deter other developers from using your styles without your permission.

As an alternative, you can use `+[MGLAccountManager setAccessToken:]` to set a token in code. See [our guide](https://www.mapbox.com/help/ios-private-access-token/) for some tips on keeping access tokens in open source code private.
As an alternative, you can use `MGLAccountManager.accessToken` to set a token in code. See [our guide](https://www.mapbox.com/help/ios-private-access-token/) for some tips on keeping access tokens in open source code private.

## MGLMapboxAPIBaseURL

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class ViewController: UIViewController {
// You can obtain your own access token from the
// [Mapbox account page](https://www.mapbox.com/studio/account/tokens/)
// and add it to this application's Info.plist as the value for MGLMapboxAccessToken
if MGLAccountManager.accessToken() == "pk.eyJ1IjoibWFwYm94IiwiYSI6ImNqYThuNnZ3NTA5MGMyd3F1cmF1eW1xaGEifQ.TdBTSHHPeT1pfLZ_6x_1vA" {
if MGLAccountManager.accessToken == "pk.eyJ1IjoibWFwYm94IiwiYSI6ImNqYThuNnZ3NTA5MGMyd3F1cmF1eW1xaGEifQ.TdBTSHHPeT1pfLZ_6x_1vA" {
accessTokenWarningView.isHidden = false
}

Expand Down
2 changes: 1 addition & 1 deletion platform/ios/src/MGLTelemetryConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN

extern NSString *const MGLMapboxMetricsProfile;

+ (nullable instancetype)sharedConfig;
@property (class, nullable, nonatomic, readonly) MGLTelemetryConfig *sharedConfig;

- (void)configurationFromKey:(NSString *)key;

Expand Down
1 change: 1 addition & 0 deletions platform/macos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* The `-[MGLMapView convertRect:toCoordinateBoundsFromView:]` method and the `MGLMapView.visibleCoordinateBounds` property’s getter now indicate that the coordinate bounds straddles the antimeridian by extending one side beyond ±180 degrees longitude. ([#11265](https://github.com/mapbox/mapbox-gl-native/pull/11265))
* Feature querying results now account for the `MGLSymbolStyleLayer.circleStrokeWidth` property. ([#10897](https://github.com/mapbox/mapbox-gl-native/pull/10897))
* Removed methods, properties, and constants that had been deprecated as of v0.6.1. ([#11205](https://github.com/mapbox/mapbox-gl-native/pull/11205))
* Refined certain Swift interfaces by converting them from class methods to class properties. ([#11674](https://github.com/mapbox/mapbox-gl-native/pull/11674))

## v0.6.1 - January 16, 2018

Expand Down
2 changes: 1 addition & 1 deletion platform/macos/docs/guides/Info.plist Keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Set the [Mapbox access token](https://www.mapbox.com/help/define-access-token/)

Mapbox-hosted vector tiles and styles require an API access token, which you can obtain from the [Mapbox account page](https://www.mapbox.com/studio/account/tokens/). Access tokens associate requests to Mapbox’s vector tile and style APIs with your Mapbox account. They also deter other developers from using your styles without your permission.

As an alternative, you can use `+[MGLAccountManager setAccessToken:]` to set a token in code. See [our guide](https://www.mapbox.com/help/ios-private-access-token/) for some tips on keeping access tokens in open source code private.
As an alternative, you can use `MGLAccountManager.accessToken` to set a token in code. See [our guide](https://www.mapbox.com/help/ios-private-access-token/) for some tips on keeping access tokens in open source code private.

## MGLMapboxAPIBaseURL

Expand Down