0

In Objective-C we filled out the ScheduledAudioFileRegion struct like so:

ScheduledAudioFileRegion playRegion;
playRegion.mTimeStamp.mFlags = kAudioTimeStampSampleTimeValid;
playRegion.mTimeStamp.mSampleTime = 0;
playRegion.mCompletionProc = NULL;
playRegion.mCompletionProcUserData = NULL;
playRegion.mAudioFile = audioFileID;
playRegion.mLoopCount = 0;
playRegion.mStartFrame = 0;
playRegion.mFramesToPlay = -1;

with the mFramesToPlay set to -1 to tell it to play the entire file.

Swift will not allow me to set a UInt32 to -1. So how do I tell it to play the entire file?

I know this is not the only place that a negative value for a UInt32 was used as a flag in Obj-C, but it's the first time I've run into it.

joelperry
  • 158
  • 2
  • 5

1 Answers1

1

mFramesToPlay is a UInt32, and Swift does not implicitly convert between signed and unsigned integers. You could write

playRegion.mFramesToPlay = UInt32(bitPattern: -1)

or just

playRegion.mFramesToPlay = UInt32.max
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382