Fanny Darmer
Fanny Darmer

Reputation: 29

AudioServicesCreateSystemSoundID and Memory Address Argument - How to pass in a property?

I have a method AudioServicesCreateSystemSoundID that according to the documentation seems to require a memory address passed in (*outSystemSoundID).

From Apple's Website...

OSStatus AudioServicesCreateSystemSoundID (
   CFURLRef       inFileURL,
   SystemSoundID  *outSystemSoundID
);

I have this code that works when I create a local object within the method. The object is assigned correctly to the memory location.

This returns myTest with code: 0 ( this is what I want )

 SystemSoundID thisSoundID;

 SystemSoundID myTest = AudioServicesCreateSystemSoundID
 (
 (__bridge CFURLRef)(url), &thisSoundID
 );

But this is what I am trying to do. (self.theSound I have set up as a SystemSoundID property).

This returns myTest with error code : 4294967246 ( I do not want this )

SystemSoundID myTest = AudioServicesCreateSystemSoundID
(
    (__bridge CFURLRef)(url), self.theSound
);

Upvotes: 0

Views: 517

Answers (1)

Martin R
Martin R

Reputation: 539795

The compiler translates self.theSound to

[self theSound]

where -(SystemSoundID)theSound is the (automatically synthesized) getter method of you property which (by default) gets the value from the _theSound instance variable.

So you cannot take the "address of a property" and pass it to a function. You could pass the address of the instance variable instead:

SystemSoundID myTest = AudioServicesCreateSystemSoundID
(
    (__bridge CFURLRef)(url), &self->_theSound
);

bypassing the property accessor. But I would recommend to use a temporary variable instead:

 SystemSoundID thisSoundID;
 SystemSoundID myTest = AudioServicesCreateSystemSoundID
 (
     (__bridge CFURLRef)(url), &thisSoundID
 );
 self.theSound = thisSoundID;

Upvotes: 1

Related Questions