AI-generated Key Takeaways
- 
          AutocompletePlaceSuggestionrepresents a full query suggestion based on a partially typed string, providing details like the place's name, location, and distance.
- 
          It offers attributed text properties (e.g., attributedFullText,attributedPrimaryText) that highlight the matching user input for clear visual representation.
- 
          Developers can access essential information such as placeIDfor further place details requests andtypesfor categorizing the suggestion.
- 
          AutocompletePlaceSuggestionconforms toEquatableandHashableprotocols, enabling comparisons and use in data structures that require these functionalities.
- 
          Legacy NSAttributedStringproperties are available for compatibility with older codebases while adopting newer Swift-based attributed strings is encouraged.
AutocompletePlaceSuggestion
struct AutocompletePlaceSuggestionextension AutocompletePlaceSuggestion : Copyable, CustomStringConvertible, Equatable, Escapable, Hashable, SendableThis 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 aandb,a == bimplies thata != bisfalse.DeclarationSwift static func == (lhs: AutocompletePlaceSuggestion, rhs: AutocompletePlaceSuggestion) -> BoolParameterslhsA value to compare. rhsAnother 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) }DeclarationSwift 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, likeattributedFullText.DeclarationSwift 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, likeattributedFullText.May be nil. DeclarationSwift 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 customdescriptionproperty for types that conform toCustomStringConvertible: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 pto a string in the assignment tosuses thePointtype’sdescriptionproperty.DeclarationSwift 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 AutocompleteFilterof the request.DeclarationSwift 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 Hashableprotocol. The components used for hashing must be the same as the components compared in your type’s==operator implementation. Callhasher.combine(_:)with each of these components.Important In your implementation of hash(into:), don’t callfinalize()on thehasherinstance provided, or replace it with a different instance. Doing so may become a compile-time error in the future.DeclarationSwift 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 hashValueis deprecated as aHashablerequirement. To conform toHashable, implement thehash(into:)requirement instead. The compiler provides an implementation forhashValuefor you.DeclarationSwift var hashValue: Int { get }
- 
                  
                  Instantiates an AutocompletePlaceSuggestionwith the specified information.This initializer can be used for testing. The AttributedStrings can be created using markdown to indicate substrings that contain theautocompleteMatchAttribute. 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))DeclarationSwift init(placeID: String, types: Set<PlaceType>, distance: Measurement<UnitLength>?, primaryText: AttributedString, secondaryText: AttributedString?)ParametersplaceIDThe id of the place. typesA set of PlaceTypesdistanceThe optional distance of the place. primaryTextThe primary attributed string. secondaryTextThe secondary attributed string. Return ValueAn AutocompletePlaceSuggestioncontaining the specified information.
- 
                  
                  Instantiates an AutocompletePlaceSuggestionwith the specified information.This initializer can be used for testing. The NSAttributedStrings contain sections withNSAttributedString.Key.autocompleteMatchto indicate substrings that contain theautocompleteMatchattribute.DeclarationSwift init(placeID: String, types: Set<PlaceType>, distance: Measurement<UnitLength>?, primaryText: NSAttributedString, secondaryText: NSAttributedString?)ParametersplaceIDThe id of the place. typesA set of PlaceTypesdistanceThe optional distance of the place. primaryTextThe primary attributed string. secondaryTextThe secondary attributed string. Return ValueAn AutocompletePlaceSuggestioncontaining 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;DeclarationSwift 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, likeattributedFullText.DeclarationSwift 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, likeattributedFullText.May be nil. DeclarationSwift var legacyAttributedSecondaryText: NSAttributedString? { get }
- 
                  
                  A property representing the place ID of the suggestion. Suitable for use in a place details request. DeclarationSwift 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. DeclarationSwift var types: Set<PlaceType> { get }