Equities have been volatile recently. The S&P 500 even flirted with bear market territory earlier this year. While it has recovered and is now in the green for the year, many companies are still down significantly. One of them is Apple (AAPL 0.07%), the tech giant that needs no introduction.

Though it remains one of the largest companies in the world by market cap, Apple has had a challenging past six months. Let's examine the headwinds the iPhone maker has faced and what they could mean for long-term investors.

Tariffs could cut into Apple's profits

The most important challenge encountered this year is President Donald Trump's trade agenda. He has been in office for less than a year, but the U.S.'s 47th President has been busy implementing -- or trying to implement -- aggressive tariffs on imports from most countries.

Trump's end goal is to force companies to bring manufacturing jobs back to the U.S. Corporations that opt not to do so will see their manufacturing expenses rise, possibly significantly, which will eat into their margins and their bottom lines. Apple finds itself in a tough spot here for at least two reasons.

Person sitting at a desk looking at two monitors.

Image source: Getty Images.

First, the tech leader does a significant amount of manufacturing in China, which the Trump administration has targeted with tariffs more than any other country. Second, making iPhones on U.S. soil might be prohibitively expensive for the company. Investors have sold off Apple's stock in response to these developments, but there is more.

Apple continues to struggle with the perception that it trails its similarly sized tech peers in the lucrative and fast-growing artificial intelligence (AI) market. The company has made some moves in the field, but they haven't been enough (at least, that's what some investors believe). Are Apple's shares still attractive despite its challenges?

The long-term view

It may be challenging for Apple to manufacture iPhones in the U.S., but other products can be made in the country. The company announced that it would spend $500 billion over the next four years to strengthen its local manufacturing capacity. These efforts will include a brand-new facility and the expansion of several existing ones. Apple will manufacture AI servers in some of these facilities, something it normally would do abroad.

While this is hardly enough to make up for the heavy tariffs the company will face if Trump's trade agenda survives his administration, it's a start. Furthermore, Apple could move manufacturing outside of China and into other countries that haven't been on Trump's radar nearly as much. So, the company could implement a multi-pronged approach to solving this problem.

It's also worth noting that Trump has been going back and forth with his tariff plans, and engaging in a series of negotiations and trade deals with various countries. It's not clear that once the dust settles, things will be as bad for Apple as some think.

Meanwhile, the tech company still has a robust underlying business, a strong competitive advantage, and important long-term growth avenues. Apple continues to generate consistent revenue and earnings, despite the challenges it has faced. The iPhone maker brand name -- one of the most valuable in the world -- remains one of its strongest sources of moat.

Apple also benefits from switching costs for its devices. Jumping ship from an iPhone to an Android isn't that easy. It requires the sometimes painful task of transferring data between the two. Furthermore, iPhone users who own other Apple devices would lose various nifty features that come with having multiple Apple products. The company's app store also benefits from network effects.

Lastly, Apple's services segment looks promising. This segment has been growing faster than the rest of its business for years. Apple has over 2 billion installed devices and over a billion paid subscriptions, and there is plenty of room to grow. The company may not be a leader in AI yet, but Apple has made a living off improving existing technologies. The tech leader isn't always first. It just knows how to add its own spin to products to make them far more appealing.

With $98.5 billion in free cash flow generated over the trailing 12-month period, Apple has the cash it needs to invest aggressively in this or other potential opportunities. That's before we even mention the company's consistent record of dividend growth over the past decade. Apple may have lagged the market this year, but the company's long-term prospects remain strong. It's still worth buying the stock today.