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

621
Views
Swift : Generic parameter 'T' could not be inferred

I have a protocol called P, and I want to write a function that would return an instance of any type conforming to that protocol.

I wrote this:

func f<T: P>() -> T? {
    // ... 
}

But then when I try to call it:

var fp = f()

I get this error: Generic parameter 'T' could not be inferred. What am I doing wrong and how to solve this? Thanks for your help.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You're very close. Say you have a struct A that conforms to P. Then you could specify the generic parameter as follows:

var fp: A? = f()

Without that information, the compiler can't know what type fp should be.

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!