GooglePlaces Framework Reference

GMSAutocompleteTableDataSource

@interface GMSAutocompleteTableDataSource
    : NSObject <UITableViewDataSource, UITableViewDelegate>

GMSAutocompleteTableDataSource provides an interface for providing place autocomplete predictions to populate a UITableView by implementing the UITableViewDataSource and UITableViewDelegate protocols.

GMSAutocompleteTableDataSource is designed to be used as the data source for a UISearchDisplayController.

NOTE: UISearchDisplayController has been deprecated since iOS 8. It is now recommended to use UISearchController with GMSAutocompleteResultsViewController to display autocomplete results using the iOS search UI.

Set an instance of GMSAutocompleteTableDataSource as the searchResultsDataSource and searchResultsDelegate properties of UISearchDisplayController. In your implementation of shouldReloadTableForSearchString, call sourceTextHasChanged with the current search string.

Use the GMSAutocompleteTableDataSourceDelegate delegate protocol to be notified when a place is selected from the list. Because autocomplete predictions load asynchronously, it is necessary to implement didUpdateAutocompletePredictions and call reloadData on the UISearchDisplayController‘s table view.

  • Delegate to be notified when a place is selected or picking is cancelled.

    Declaration

    Swift

    @IBOutlet weak var delegate: (any GMSAutocompleteTableDataSourceDelegate)? { get set }

    Objective-C

    @property (nonatomic, weak, nullable) id<GMSAutocompleteTableDataSourceDelegate> delegate;
  • Filter to apply to autocomplete suggestions (can be nil).

    Declaration

    Swift

    var autocompleteFilter: GMSAutocompleteFilter? { get set }

    Objective-C

    @property (nonatomic, strong, nullable) GMSAutocompleteFilter *autocompleteFilter;
  • The background color of table cells.

    Declaration

    Swift

    var tableCellBackgroundColor: UIColor { get set }

    Objective-C

    @property (nonatomic, strong) UIColor *_Nonnull tableCellBackgroundColor;
  • The color of the separator line between table cells.

    Declaration

    Swift

    var tableCellSeparatorColor: UIColor { get set }

    Objective-C

    @property (nonatomic, strong) UIColor *_Nonnull tableCellSeparatorColor;
  • The color of result name text in autocomplete results

    Declaration

    Swift

    var primaryTextColor: UIColor { get set }

    Objective-C

    @property (nonatomic, strong) UIColor *_Nonnull primaryTextColor;
  • The color used to highlight matching text in autocomplete results

    Declaration

    Swift

    var primaryTextHighlightColor: UIColor { get set }

    Objective-C

    @property (nonatomic, strong) UIColor *_Nonnull primaryTextHighlightColor;
  • The color of the second row of text in autocomplete results.

    Declaration

    Swift

    var secondaryTextColor: UIColor { get set }

    Objective-C

    @property (nonatomic, strong) UIColor *_Nonnull secondaryTextColor;
  • The tint color applied to controls in the Autocomplete view.

    Declaration

    Swift

    var tintColor: UIColor? { get set }

    Objective-C

    @property (nonatomic, strong, nullable) UIColor *tintColor;
  • The GMSPlaceField for specifying explicit place details to be requested. Default returns all available fields.

    Declaration

    Swift

    var placeFields: GMSPlaceField { get set }

    Objective-C

    @property (nonatomic) GMSPlaceField placeFields;
  • The GMSPlaceProperty for specifying explicit place details to be requested. Default returns all available properties.

    Declaration

    Swift

    var placeProperties: [String] { get set }

    Objective-C

    @property (nonatomic, strong) NSArray<NSString *> *_Nonnull placeProperties;
  • Initializes a data source.

    Declaration

    Swift

    init()

    Objective-C

    - (nonnull instancetype)init;
  • Notify the data source that the source text to autocomplete has changed.

    This method should only be called from the main thread. Calling this method from another thread will result in undefined behavior. Calls to GMSAutocompleteTableDataSourceDelegate methods will also be called on the main thread.

    This method is non-blocking.

    Declaration

    Swift

    func sourceTextHasChanged(_ text: String?)

    Objective-C

    - (void)sourceTextHasChanged:(nullable NSString *)text;

    Parameters

    text

    The partial text to autocomplete.

  • Clear all predictions.

    NOTE: This will call the two delegate methods below:

    • didUpdateAutocompletePredictionsForResultsController:
    • didRequestAutocompletePredictionsForResultsController:

    The implementation of this method is guaranteed to call these synchronously and in-order.

    Declaration

    Swift

    func clearResults()

    Objective-C

    - (void)clearResults;