Here’s the good news for Apple.

Its surprise settlement with Qualcomm Tuesday over a years-long patent spat means it’s now in a position to keep pace with its competitors to bring a 5G-ready iPhone to market as soon as this year.

But even though Apple may win by getting a 5G iPhone to customers sooner than most people anticipated, it lost by settling with a company it loathes. Getting the iPhone to 5G means Apple was put in a sticky situation where it had to weigh four less-than-ideal options to make it all a reality.

In the end, Apple had to choose the lesser of all evils:

Option one: Settle with Qualcomm, the leader in 5G chips. Qualcomm’s 5G chips are already shipping in some devices today, with more expected as the year rolls on.

But Apple has seen Qualcomm’s business model as detrimental to the entire industry since it uses its dominant position to squeeze large fees out of each company that uses its chips and patents. Hence that nasty lawsuit. Apple CEO Tim Cook made his disdain for Qualcomm’s practices known in a January interview with CNBC’s Jim Cramer, and even blasted Qualcomm’s decision to hire a PR firm to write fake news stories about Apple.

Option two: Wait for Intel to catch up in 5G. Even before Intel announced Tuesday night that it would abandon its plans to make 5G modems, there was speculation that the company was running behind to deliver the chips on time. Apple has been exclusively using Intel’s 4G modems in its latest iPhones as its dispute with Qualcomm raged on. If that dispute continued, a 5G iPhone might not have been possible until 2020 or even 2021.

Option three: Choose Huawei. In an interview with CNBC this week, Huawei’s CEO said the company was “open” to talks with Apple about bringing its 5G chips to the iPhone. But a partnership with Huawei would’ve looked bad for Apple, given the stink of political and security concerns around the company.

Option four: Apple could make its own 5G chips. Apple is thought to be working on its own modems after opening an office in San Diego, Qualcomm’s hometown, and posting job listings for modem chip designers. But it would likely take Apple several years to develop its own 5G chip, putting it several years behind its rivals.

None of those options were ideal for Apple. It could’ve waited an extra year or two for Intel to get its 5G chips up to snuff. It could’ve waited several more years to develop a 5G chip of its own as competitors like Google and Samsung push out their 5G devices and market themselves as more innovative than Apple. It could’ve worked with Huawei, a company that still can’t sell products in the U.S. over security concerns.

Or it could’ve ended its dispute with Qualcomm, even if Apple CEO Tim Cook is allergic to its business practices. Unfortunately for Apple, Qualcomm was the best bet.

Tuesday’s settlement could result in a 5G iPhone as soon as this fall, when Apple is expected to release its next iPhone. (For what it’s worth, timing on a 5G iPhone is still unclear. Qualcomm’s CEO Steve Mollenkopf said in an interview on CNBC’s “Squawk Box” Wednesday that he couldn’t comment on Apple’s product plans that include Qualcomm chips.)

Qualcomm gets to take a victory lap this week. Its lead in 5G forced a settlement with Apple and added a massive boost to its stock. Qualcomm’s stock was up 12 percent Wednesday, adding to its 23 percent gain Tuesday. Intel was up about 4 percent. Apple was up just 1 percent.

The market agrees. Apple was the loser in this fight.