Apple (AAPL 0.06%) stock is coming out of a solid growth year, with its shares climbing 48% in 2023. However, the company's stock performance doesn't tell the whole story.

Macroeconomic headwinds caught up with Apple last year, causing reductions in consumer spending and repeated declines in product sales. Meanwhile, the company had to contend with restrictions on its smartphones in China and a potential patent infringement with its new Apple Watch. The issues culminated in a 3% year over year decline in revenue for the company's fiscal 2023.

However, Apple remains a tech behemoth with vast financial resources. Its reputation saw investors stick with the company even through challenging market conditions last year, illustrated by its stock growth. The company is in a slump, but it's unlikely to last forever.

Here's why it's not too late to buy Apple stock -- but be prepared to hold for the long term.

Market headwinds that may finally be resolving

Over the last two years, spikes in inflation saw consumers cut discretionary spending and shy away from annual upgrades to their devices. For Apple, this shift was reflected in revenue declines in each of its product segments. In fiscal 2023, net sales for the iPhone fell by 2% year over year, with Mac revenue plunging 27% and iPad sales sliding 3%.

Apple suffered from declines that affected companies across tech. According to International Data Corporation (IDC), global smartphone shipments decreased 11% in 2022 and continued falling for most of 2023. Other tech markets, like personal computers, saw similar declines during the period.

However, recent data shows a rebound in the industry may have begun. Smartphone shipments rose for the first time in over a year in the fourth quarter of 2023, with IDC reporting a 7% increase. The recovery is projected to continue this year and rise close to 4% in 2024.

Apple's iPhone segment accounts for more than 50% of its revenue, which made it vulnerable to a market downturn in 2023. However, there may be some light at the end of the tunnel now that tech sales are on the rise and the company is expanding into other sectors.

It's not too late, but you'll need to be patient

Apple hit nearly $100 billion in free cash flow last year despite declines in its product segment. The figure indicates that Apple has the financial resources to invest heavily in its business and overcome current headwinds.

It's encouraging that Apple increased its research and development spending by close to $4 billion last year, using about 8% of its revenue. The chart below shows that's the highest percentage spent on research for at least 20 years. In fact, the last time it was higher, Apple was gearing up to release the first iPhone and expand its iPod business.

AAPL Research and Development Expense (% of Annual Revenues) Chart

Data by YCharts

It's unclear what Apple's roadmap looks like for the next decade. However, it almost certainly includes artificial intelligence (AI) and virtual/augmented reality (VR/AR), two rapidly expanding industries.

The AI market on its own is projected to develop at a compound annual growth rate (CAGR) of 37% through 2030, which would see it surpass a value of $1 trillion. Meanwhile, VR is on a similar trajectory, with the sector expanding at a CAGR of 29% over the same period.

Apple CEO Tim Cook has hinted that a significant portion of its research is currently dedicated to AI, with Bloomberg reporting last year that the company had built a large language model similar to OpenAI's ChatGPT. So far, Apple has used AI to enhance its products, including improvements to Siri and various AI-enabled iPhone and Apple Watch features. However, significant investment could suggest something much bigger is in the works.

Regarding VR/AR, Apple will launch its first headset, the Vision Pro, next month. The new device will debut at $3,499, pricing out many consumers.

However, the headset appears to be a long-term play for Apple to eventually dominate the high-growth sector. Employing a strategy it has often used with past products, the company will likely bring down the cost of the Vision Pro with future iterations while it uses this time to create hype and refine the technology.

AMZN PE Ratio Chart

Data by YCharts

Apple's price-to-earnings ratio of 30 and price-to-sales ratio above 7 suggests its stock is a pricy option. However, comparing those figures to other companies in "Big Tech" shows Apple is actually one of the cheapest stocks besides Alphabet.

It will take time, but an improving consumer market and heavy investment in multiple high-growth areas could spell a lucrative future for Apple. Recent moves see the company expanding its economic moat, which will increase its competitive edge against rivals. As a result, it's not too late to invest in Apple, with its stock an attractive long-term option.