I was told that I need an NIE (foreigner's ID number) to rent an apartment but I need a residence address to get an NIE. The advice was to use a friend's address and then change it after getting the apartment. I don't have any close friends there but there are people I can ask. But I don't want to ask if it would result in them getting a bunch of mail from the government--mail addressed to me when I wouldn't be there to receive it (and in fact they wouldn't be there to give it to me because they are temporarily out of the country)
(Disclaimer: I'm an EU Citizen and don't have experience of doing this for a non-EU citizen - your experience may vary).
The Spanish Police/Ministry of the Interior themselves don't use the address on your NIE to send you any mail, however in order to get a NIE you need to present a Certificado de Empadronamiento (Population Register certificate) from your Ayuntamiento (Town Hall), and they do use it for voting, for tax purposes etc. You'd need some kind of authorisation from your friend saying that you're resident at their address in order to get your Certificado de Empadronamiento - and if you change that registration as soon as your have your own rental contract (and then change at the Foreigners' Office as well if required - I was told it wasn't in Barcelona but again your mileage may vary) then no post should go to your friends at all.
If you're an EU Citizen, you should be able to sign a rental contract using your passport or national ID card as ID and using that number, then present that contract at the Ayuntamiento to get a Certificado de Empadronamiento, use that certificate to get a NIE and then finally provide that NIE to the landlord.
Another option might be to apply for a NIE in your country of residence (assuming this isn't Spain) at the Spanish consulate, I've just checked the first consulate site I found on Google (Edinburgh) and they say it takes about three weeks.
When I went to the Comisaría de Extranjería to ask about it, they told me to use the address of the hostel that I was staying in while I looked for an apartment. And they sent the letter there (after insisting that they always notify by text message).
Several non-EU people who had been there for years said you cannot buy or rent without a bank account and NIE and you cannot get a bank account without NIE. Realtors and bankers confirmed this.
But while waiting for the text message that never came, I opened a bank account and signed a lease. The lights and water are also now in my name. And I still don't have a NIE. They saw the entrance stamp from April 2016 and without (apparently) looking further assumed an overstay and ordered me to leave. Some immigrant advocacy group wrote a three-page letter quoting various laws, attaching my proof that I had not overstayed, and demanding they fix it within five days. The Comisaría filed it and apparently ignored it over a month ago.