View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vídeos

Abrir menu Fechar menu
  • Coleções
  • Todos os vídeos
  • Sobre

Mais vídeos

  • Sobre
  • Código
  • Generalize APIs with parameter packs

    Swift parameter packs are a powerful tool to expand what is possible in your generic code while also enabling you to simplify common generic patterns. We'll show you how to abstract over types as well as the number of arguments in generic code and simplify common generic patterns to avoid overloads.

    To get the most out of this session, we recommend first checking out “Embrace Swift generics" from WWDC22.

    Capítulos

    • 0:00 - Introduction
    • 0:52 - What parameter packs solve
    • 4:08 - How to read parameter packs
    • 12:06 - Using parameter packs
    • 17:22 - Wrap up

    Recursos

      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    WWDC23

    • What’s new in Swift

    WWDC22

    • Design protocol interfaces in Swift
    • Embrace Swift generics
  • Buscar neste vídeo...
    • 1:13 - radians function

      func radians(from degrees: Double) -> Double
    • 1:26 - Array type

      struct Array<Element>
    • 1:48 - radians function and Array type with concrete expressions

      func radians(from degrees: Double) -> Double
      radians(from: 180)
      
      struct Array<Element>
      Array<Int>
    • 2:04 - generic query

      func query<Payload>(_ item: Request<Payload>) -> Payload
    • 2:22 - variadic query

      func query(_ item: Request...)
    • 3:16 - generic query

      func query<Payload>(_ item: Request<Payload>) -> Payload
    • 3:23 - two query overloads

      func query<Payload>(
          _ item: Request<Payload>
      ) -> Payload
      
      func query<Payload1, Payload2>(
          _ item1: Request<Payload1>,
          _ item2: Request<Payload2>
      ) -> (Payload1, Payload2)
    • 3:28 - three query overloads

      func query<Payload>(
          _ item: Request<Payload>
      ) -> Payload
      
      func query<Payload1, Payload2>(
          _ item1: Request<Payload1>,
          _ item2: Request<Payload2>
      ) -> (Payload1, Payload2)
      
      func query<Payload1, Payload2, Payload3>(
          _ item1: Request<Payload1>,
          _ item2: Request<Payload2>,
          _ item3: Request<Payload3>
      ) -> (Payload1, Payload2, Payload3)
    • 3:31 - four query overloads with extra argument error

      func query<Payload>(
          _ item: Request<Payload>
      ) -> Payload
      
      func query<Payload1, Payload2>(
          _ item1: Request<Payload1>,
          _ item2: Request<Payload2>
      ) -> (Payload1, Payload2)
      
      func query<Payload1, Payload2, Payload3>(
          _ item1: Request<Payload1>,
          _ item2: Request<Payload2>,
          _ item3: Request<Payload3>
      ) -> (Payload1, Payload2, Payload3)
      
      func query<Payload1, Payload2, Payload3, Payload4>(
          _ item1: Request<Payload1>,
          _ item2: Request<Payload2>,
          _ item3: Request<Payload3>,
          _ item4: Request<Payload4>
      ) -> (Payload1, Payload2, Payload3, Payload4)
      
      let _ = query(r1, r2, r3, r4, r5)
    • 5:52 - for-in loop over requests

      for request in requests {
          evaluate(request)
      }
    • 8:41 - four query overloads

      func query<Payload>(
          _ item: Request<Payload>
      ) -> Payload
      
      func query<Payload1, Payload2>(
          _ item1: Request<Payload1>,
          _ item2: Request<Payload2>
      ) -> (Payload1, Payload2)
      
      func query<Payload1, Payload2, Payload3>(
          _ item1: Request<Payload1>,
          _ item2: Request<Payload2>,
          _ item3: Request<Payload3>
      ) -> (Payload1, Payload2, Payload3)
      
      func query<Payload1, Payload2, Payload3, Payload4>(
          _ item1: Request<Payload1>,
          _ item2: Request<Payload2>,
          _ item3: Request<Payload3>,
          _ item4: Request<Payload4>
      ) -> (Payload1, Payload2, Payload3, Payload4)
    • 9:37 - parameter pack query interface

      func query<each Payload>(_ item: repeat Request<each Payload>) -> (repeat each Payload)
    • 10:01 - parameter pack query with single argument call

      func query<each Payload>(_ item: repeat Request<each Payload>) -> (repeat each Payload)
      
      let result = query(Request<Int>())
    • 10:08 - parameter pack query with single and triple argument calls

      func query<each Payload>(_ item: repeat Request<each Payload>) -> (repeat each Payload)
      
      let result = query(Request<Int>())
      
      let results = query(Request<Int>(), Request<String>(), Request<Bool>())
    • 10:15 - parameter pack query with triple argument call

      func query<each Payload>(_ item: repeat Request<each Payload>) -> (repeat each Payload)
      
      let results = query(Request<Int>(), Request<String>(), Request<Bool>())
    • 10:56 - parameter pack query interface

      func query<each Payload>(
          _ item: repeat Request<each Payload>
      ) -> (repeat each Payload)
    • 11:03 - parameter pack query interface with conformance

      func query<each Payload: Equatable>(
        _ item: repeat Request<each Payload>
      ) -> (repeat each Payload)
    • 11:17 - parameter pack query interface with where clause

      func query<each Payload>(
          _ item: repeat Request<each Payload>
      ) -> (repeat each Payload)
          where repeat each Payload: Equatable
    • 11:44 - parameter pack query interface with minimum parameter count

      func query<FirstPayload, each Payload>(
          _ first: Request<FirstPayload>, _ item: repeat Request<each Payload>
      ) -> (FirstPayload, repeat each Payload) 
          where FirstPayload: Equatable, repeat each Payload: Equatable
    • 13:42 - parameter pack query implementation

      struct Request<Payload> {
          func evaluate() -> Payload
      }
      
      func query<each Payload>(_ item: repeat Request<each Payload>) -> (repeat each Payload) {
          return (repeat (each item).evaluate())
      }
    • 16:04 - parameter pack query implementation with different input and output types

      protocol RequestProtocol {
          associatedtype Input
          associatedtype Output
          func evaluate(_ input: Input) -> Output
      }
      
      struct Evaluator<each Request: RequestProtocol> {
          var item: (repeat each Request)
      
          func query(_ input: repeat (each Request).Input) -> (repeat (each Request).Output) {
              return (repeat (each item).evaluate(each input))
          }
      }
    • 17:05 - parameter pack query implementation with control flow break

      protocol RequestProtocol {
          associatedtype Input
          associatedtype Output
          func evaluate(_ input: Input) throws -> Output
      }
      
      struct Evaluator<each Request: RequestProtocol> {
          var item: (repeat each Request)
      
          func query(_ input: repeat (each Request).Input) -> (repeat (each Request).Output)? {
              do {
                  return (repeat try (each item).evaluate(each input))
              } catch {
                  return nil
              }
          }
      }

Developer Footer

  • Vídeos
  • WWDC23
  • Generalize APIs with parameter packs
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program
    • Mini Apps Partner Program
    • News Partner Program
    • Video Partner Program
    • Security Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines