There are several different theories on how New York City earned the nickname "The Big Apple," each with a certain amount of truth to them. It appears that city officials did not officially adopt the moniker until 1971, although many residents and visitors had been using the nickname since the 1920s. The 1971 campaign to popularize New York City as the Big Apple included volunteers handing out real apples to passing tourists. Through this promotion, the city hoped to generate a more positive perception of New York City, and all it had to offer as one of the world's largest cities.
The first reference to New York City as by this name is believed to have appeared in 1909. A man named Martin Wayfarer allegedly criticized the disproportional amount of the nation's money New York City received annually. He compared the country's economy to a tree with many roots, but the "big apple" (New York City) received the bulk of the "sap." It's very possible that residents of New York City may have embraced that critical reference as a source of civic pride. Living in the city meant enjoying the benefits of a robust economy.
There is also a very popular theory involving a New York sportswriter named John J. Fitzgerald, who wrote primarily about horse racing during the 1920s. It is believed that horse races held in tracks surrounding New York City were called apples, perhaps as a reference to the prizes awarded to the winners. Fitzgerald took a trip to a stable in New Orleans in 1920, ostensibly to sell one of his own horses. Fitzgerald spoke with several jockeys while he was there, and they all referred to the New York City horse racing scene as the "Big Apple". Fitzgerald later named his regular newspaper column "Notes from Around the Big Apple," most likely inspired by the words of the jockeys from New Orleans.
Another popular but largely unsubstantiated theory centers around the world of jazz music. Musicians during the Jazz Age were said to call paying gigs "apples", for reasons known only to themselves. By the 1920s, New York City had established itself as one of the premiere cities for jazz music, so it became the destination of many working jazz musicians. The ultimate gig for a musician was to play the "Big Apple," meaning a nightclub in New York City. New York City became a destination for other entertainers as well, which could explain why the nickname became so popular.