GooglePlacesSwift Framework Reference

AutocompletePlaceSuggestion

struct AutocompletePlaceSuggestion
extension AutocompletePlaceSuggestion : CustomStringConvertible, Equatable, Hashable

This class represents a suggestion of a full query based on a partially typed string. */

  • Returns a Boolean value indicating whether two values are equal.

    Equality is the inverse of inequality. For any values a and b, a == b implies that a != b is false.

    Declaration

    Swift

    static func == (lhs: AutocompletePlaceSuggestion, rhs: AutocompletePlaceSuggestion) -> Bool

    Parameters

    lhs

    A value to compare.

    rhs

    Another value to compare.

  • The full description of the suggestion as a AttributedString.

    E.g., “Sydney Opera House, Sydney, New South Wales, Australia”.

    Every text range that matches the user input has an autocompleteMatchAttribute. For example, you can make every match bold this way:

    let boldFont = UIFont.boldSystemFont(ofSize: UIFont.labelFontSize)
    
    var bolded: AttributedString = suggestion.attributedFullText
    guard let sourceAttributes = try? AttributeContainer(
      [.autocompleteMatch: ""],
      including: \.googlePlaces)
    else { return }
    
    let finalAttributes = sourceAttributes.merging(AttributeContainer([.font : boldFont]))
    
    bolded.replaceAttributes(sourceAttributes, with: finalAttributes)
    
    var Body: some View {
      Text(bolded)
    }
    

    Declaration

    Swift

    var attributedFullText: AttributedString { get }
  • The main text of a suggestion as a AttributedString, usually the name of the place.

    E.g. “Sydney Opera House”.

    Text ranges that match user input are have a autocompleteMatchAttribute, like attributedFullText.

    Declaration

    Swift

    var attributedPrimaryText: AttributedString { get }
  • The secondary text of a suggestion as an AttributedString, usually the location of the place.

    E.g. “Sydney, New South Wales, Australia”.

    Text ranges that match user input are have a autocompleteMatchAttribute, like attributedFullText.

    May be nil.

    Declaration

    Swift

    var attributedSecondaryText: AttributedString? { get }
  • A textual representation of this instance.

    Calling this property directly is discouraged. Instead, convert an instance of any type to a string by using the String(describing:) initializer. This initializer works with any type, and uses the custom description property for types that conform to CustomStringConvertible:

    struct Point: CustomStringConvertible {
        let x: Int, y: Int
    
        var description: String {
            return "(\(x), \(y))"
        }
    }
    
    let p = Point(x: 21, y: 30)
    let s = String(describing: p)
    print(s)
    // Prints "(21, 30)"
    

    The conversion of p to a string in the assignment to s uses the Point type’s description property.

    Declaration

    Swift

    var description: String { get }
  • The straight line distance in meters between the origin and this suggestion.

    Only available if a valid origin is specified in the AutocompleteFilter of the request.

    Declaration

    Swift

    var distance: Measurement<UnitLength>? { get }
  • Hashes the essential components of this value by feeding them into the given hasher.

    Implement this method to conform to the Hashable protocol. The components used for hashing must be the same as the components compared in your type’s == operator implementation. Call hasher.combine(_:) with each of these components.

    Important

    In your implementation of hash(into:), don’t call finalize() on the hasher instance provided, or replace it with a different instance. Doing so may become a compile-time error in the future.

    Declaration

    Swift

    func hash(into hasher: inout Hasher)
  • The hash value.

    Hash values are not guaranteed to be equal across different executions of your program. Do not save hash values to use during a future execution.

    Important

    hashValue is deprecated as a Hashable requirement. To conform to Hashable, implement the hash(into:) requirement instead. The compiler provides an implementation for hashValue for you.

    Declaration

    Swift

    var hashValue: Int { get }
  • Instantiates an AutocompletePlaceSuggestion with the specified information.

    This initializer can be used for testing.

    The AttributedStrings can be created using markdown to indicate substrings that contain the autocompleteMatchAttribute. eg:

    let key = AttributeScopes.GooglePlacesAttributes.AutocompleteMatchAttribute.markdownName
    let primaryText = try AttributedString(
      markdown: "^[Moun](\(key): '')tain ^[View](\(key): ''), CA",
      including: \.googlePlaces
      options: AttributedString.MarkdownParsingOptions(allowsExtendedAttributes: true))
    

    Declaration

    Swift

    init(placeID: String, types: Set<PlaceType>, distance: Measurement<UnitLength>?, primaryText: AttributedString, secondaryText: AttributedString?)

    Return Value

    An AutocompletePlaceSuggestion containing the specified information.

  • Instantiates an AutocompletePlaceSuggestion with the specified information.

    This initializer can be used for testing.

    The NSAttributedStrings contain sections with NSAttributedString.Key.autocompleteMatch to indicate substrings that contain the autocompleteMatch attribute.

    Declaration

    Swift

    init(placeID: String, types: Set<PlaceType>, distance: Measurement<UnitLength>?, primaryText: NSAttributedString, secondaryText: NSAttributedString?)

    Return Value

    An AutocompletePlaceSuggestion containing the specified information.

  • The full description of the suggestion as a NSAttributedString.

    E.g., “Sydney Opera House, Sydney, New South Wales, Australia”.

    Every text range that matches the user input has a autocompleteMatch. For example, you can make every match bold using enumerateAttribute:

      UIFont ///regularFont = [UIFont systemFontOfSize:[UIFont labelFontSize]];
      UIFont ///boldFont = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
    
      NSMutableAttributedString ///bolded = [suggestion.attributedFullText mutableCopy];
      [bolded enumerateAttribute:autocompleteMatch
                         inRange:NSMakeRange(0, bolded.length)
                         options:0
                      usingBlock:^(id value, NSRange range, BOOL ///stop) {
                        UIFont ///font = (value == nil) ? regularFont : boldFont;
                        [bolded addAttribute:NSFontAttributeName value:font range:range];
                      }];
    
      label.attributedText = bolded;
    

    Declaration

    Swift

    var legacyAttributedFullText: NSAttributedString { get }
  • The main text of a suggestion as a NSAttributedString, usually the name of the place.

    E.g. “Sydney Opera House”.

    Text ranges that match user input are have a autocompleteMatch, like attributedFullText.

    Declaration

    Swift

    var legacyAttributedPrimaryText: NSAttributedString { get }
  • The secondary text of a suggestion as a NSAttributedString, usually the location of the place.

    E.g. “Sydney, New South Wales, Australia”.

    Text ranges that match user input are have a autocompleteMatch, like attributedFullText.

    May be nil.

    Declaration

    Swift

    var legacyAttributedSecondaryText: NSAttributedString? { get }
  • A property representing the place ID of the suggestion.

    Suitable for use in a place details request.

    Declaration

    Swift

    var placeID: String { get }
  • The types of this autocomplete result.

    Types are Strings, valid values are any types documented at https://developers.google.com/places/ios-sdk/supported_types.

    Declaration

    Swift

    var types: Set<PlaceType> { get }