Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
How to access associated value of a switch case, which itself is in a trailing closure

As follows, what expression should I write to access let learningList? In the code, query is a class, find is a function. Many thanks!

        _ = query.find { result in
            switch result  {
            case .success(objects: let learningList):
                break
            case .failure(error: let error):
                print(error)
            
            }
        }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

That is a local variable, so you can access it only in the decelerated context, i.e. inside case. If you need to use it later you have to create a property in caller class to hold it, like

_ = query.find { [weak self] result in     // << ref to caller
    switch result  {
    case .success(objects: let learningList):
        self?.learningList = learningList     // << safe in caller's property
        break
    case .failure(error: let error):
        print(error)
    
    }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!