It hasn't been an easy year for Apple (AAPL 0.72%), with macroeconomic headwinds curbing spending across the consumer tech sector. Poor market conditions caused repeated declines in Apple's product segments, with revenue tumbling 3% year over year in its fiscal 2023. Yet despite the challenges, the company's stock has risen 45% year to date.

Investors have largely stayed loyal to the iPhone manufacturer as its history of reliability and sustained dominance in tech has overshadowed recent challenges. Their devotion to the tech giant is not unfounded, with Apple continuing to outperform the competition and delivering an impressive balance sheet.

With nearly $100 billion in free cash flow and $162 billion in cash and marketable securities in 2023, Apple has the funds to overcome temporary headwinds and continue investing in its business. The tech giant is a reliable buy, with the company likely to flourish over the long term.

Here are two excellent reasons to buy Apple stock now.

1. It's been outperforming the competition

As the world's most valuable company with a market capitalization close to $3 trillion, Apple has a long history of outperforming its peers. This chart shows how Apple's stock has delivered significantly more growth over the past five years than some of its biggest competitors.

AAPL Chart

Data by YCharts

Apple has benefited from immense brand loyalty, developing a strategic ecosystem for its products that keeps consumers coming back. In April, Warren Buffett said, "If someone offered you $10,000 to never buy an iPhone again, you wouldn't take it." While surprising, the sentiment rings true for millions of consumers who would sooner give up countless other brands before abandoning Apple.

The public's preference for Apple's devices has been particularly clear during recent market declines. Counterpoint Research shows smartphone shipments fell 19% year over year in Q3 2023, with Samsung and Alphabet's sales plunging 26% and 37%, respectively. Meanwhile, Apple's iPhone shipments decreased a much more moderate 11%, allowing it to retain its majority market share.

Apple's business has proved vulnerable to economic declines this year, but its dominance in tech means it has much to gain from the market's inevitable recovery.

2. It's home to a highly profitable services business

While Apple waits for the tech market to bounce back, it is benefiting from consistent gains in its services segment. The digital business includes income from the App Store and subscription platforms like Apple TV+, Music, and iCloud.

Services have blown up in recent years, becoming Apple's second-highest-earning segment after the iPhone and delivering attractive profit margins of 70%. By comparison, products' profit margins hover around 36%.

Moreover, services have proven far less vulnerable to economic fluctuation, with the segment's revenue rising 9% year over year in fiscal 2023 while iPhone net sales tumbled 2%. So it's not surprising that Apple is increasing the priority it places on digital offerings as it works to strengthen its business over the long term and lean less on product sales.

In addition to a wide range of subscription services, the company is heavily investing in artificial intelligence (AI). Apple's research and development spending increased by over $3 billion in 2023, with CEO Tim Cook attributing the rise to a more significant focus on generative AI.

The tech giant has reportedly developed an AI chatbot and is gradually bringing AI upgrades across its product lineup. Apple might not be as far into its AI journey as companies like Microsoft and Alphabet, but I wouldn't count it out over the long term.

Apple is known for slightly hanging back when it comes to new technology, learning from the mistakes of its competitors and then making big waves with the release of a polished product. As demand for AI services rises, Apple is well-positioned to become a major player in the market by utilizing the popularity of its products to attract billions of users to its AI offerings.

Apple's history of reliability, promising balance sheet, and growing services business make the company's stock an attractive investment right now and one to buy like there's no tomorrow.