0

I am new to iOS,I have Implemented Background mail using SMTP Server,While Integrating with Main Project I am getting (passing address of non-local object to _autoreleasing parameter for write-back) this error I don't know how to solve that ,I referred this link to implement Background Mail. I have used this SMTP library link Below line getting error,

[NSStream getStreamsToHostNamed:relayHost port:relayPort inputStream:&inputStream outputStream:&outputStream];
Shubam Gupta
  • 61
  • 1
  • 11

1 Answers1

0

Under ARC a parameter declared as:

SomeObjectType ** parameterName

has the implicit ownership qualifier of __autoreleasing:

SomeObjectType * __autoreleasing * parameterName

Such parameters are out parameters, that is they receive a value from the called method rather than pass a value to the called method, and the actual parameter must be the address of a local variable. This mechanism is referred to as pass-by-writeback.

The error message is telling you that one or both of addresses you have passed are not those of local variables, i.e. either or both of inputStream or outputStream are not local variables.

The simple fix is to introduce local variables to use for the parameters and after the call copy the returned values into your non-local variables:

NSInputStream *tempInputStream;
NSOutputStream *tempOutputStream;
[NSStream getStreamsToHostNamed:relayHost port:relayPort inputStream:&tempInputStream outputStream:&tempOutputStream];
// copy return values to non-local variables
inputStream = tempInputStream;
outputStream = tempOutputStream;

If you wish to understand the reasons why out parameters only accept local variables read Passing to an out parameter by writeback in Apple's Clang documentation.

HTH

CRD
  • 52,522
  • 5
  • 70
  • 86