Migrating to GMSPlaceField as NS_OPTIONS

Beginning with Version 4.0.0 of the Places SDK for iOS, the GMSPlaceField type now uses the NS_OPTIONS macro. Versions 3.x of the SDK have GMSPlaceField as NS_ENUM and are still supported.

  • If you are using Objective-C: there are no implications. You can continue using GMSPlaceField as before.

  • If you are using Swift: Your implementation will break if you are using the GMSPlaceField(rawValue:) syntax as the constructor, which older versions of the SDK returned as an optional GMSPlaceField?. Version 4.0.0 and higher returns a non-optional GMSPlaceField value; any operations that are performed on the optional, such as conditional checks or force unwraps, will fail. In addition, you may now use array syntax to combine GMSPlaceFields

Migrate your code

Certain conditional unwrapping or force unwrapping syntaxes will break in Swift. The following examples show how to fix these issues, and also demonstrate using array syntax to declare GMSPlaceField:

Conditional unwrapping

The statement in the following example shows using if to create a GMSPlaceField array which requires conditional unwrapping. This will result in a compiler error ("Initializer for conditional binding must have Optional type, not GMSPlaceField".)

// Before.
if let field = GMSPlaceField(
    rawValue: GMSPlaceField.name.rawValue | GMSPlaceField.photos.rawValue
) { // Do something }

To fix this issue, remove the if statement, as shown here:

// After.
let field =  GMSPlaceField(
    rawValue: GMSPlaceField.name.rawValue | GMSPlaceField.photos.rawValue
)
// Do something

You can also use array syntax, as shown here:

let field = [GMSPlaceField.name, GMSPlaceField.photos]
// or
let field: GMSPlaceField = [.name, .photos]

Force unwrapping

The statement in the following example shows using GMSPlaceField as a non- optional type. This will result in a compiler error ("Cannot force unwrap value of non-optional type GMSPlaceField."):

// Before.
let field = GMSPlaceField(
    rawValue: GMSPlaceField.name.rawValue | GMSPlaceField.photos.rawValue
)!

To fix this issue, use GMSPlaceField as an optional type, as shown here:

// After.
let field =  GMSPlaceField(
    rawValue: GMSPlaceField.name.rawValue | GMSPlaceField.photos.rawValue
)

You can also use array syntax, as shown here:

let field = [GMSPlaceField.name, GMSPlaceField.photos]
// or
let field: GMSPlaceField = [.name, .photos]