2

This is a couple lines of code taken pretty much verbatim from the GBA4iOS controller view that changes the length of a vibration:

void AudioServicesStopSystemSound(int);
void AudioServicesPlaySystemSoundWithVibration(int, id, NSDictionary *);

@implementation vibeObject;

- (void)vibrate
{
    AudioServicesStopSystemSound(kSystemSoundID_Vibrate);

    int64_t vibrationLength = 30;

    NSArray *pattern = @[@NO, @0, @YES, @(vibrationLength)];

    NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
    dictionary[@"VibePattern"] = pattern;
    dictionary[@"Intensity"] = @1;

    AudioServicesPlaySystemSoundWithVibration(kSystemSoundID_Vibrate, nil, dictionary);
}

@end

My attempt here just refuses to work under all circumstances:

func AudioServicesStopSystemSound(Int);
func AudioServicesPlaySystemSoundWithVibration(Int , NilLiteralConvertible, NSDictionary)();

func vibrate(){

    AudioServicesStopSystemSound(kSystemSoundID_Vibrate);

    let vibrationLength = 30;

    let pattern: NSArray = [false, 0, true, vibrationLength];

    var dictionary:NSMutableDictionary;
    dictionary["VibePattern"] = pattern;
    dictionary["Intensity"] = 1;

    AudioServicesPlaySystemSoundWithVibration(kSystemSoundID_Vibrate, nil, dictionary);
}

When left uncommented, it crashes SourceKit, but only in view controller. When I put it in its own file:

vibeObject.vibrate(<# RIGHT HERE IT TELLS ME "EXPECTED ',' SEPARATOR vibeObject#>);

I've tried everything I could, if you could help it'd be greatly appreciated

Frank
  • 21
  • 1

2 Answers2

0

Remove the set of parenthesis after your "AudioServicesPlaySystemSoundWithVibration" declaration.

From:

func AudioServicesPlaySystemSoundWithVibration(Int , NilLiteralConvertible, NSDictionary)();

To:

func AudioServicesPlaySystemSoundWithVibration(Int , NilLiteralConvertible, NSDictionary);
chrissukhram
  • 2,957
  • 1
  • 13
  • 13
0

First, you don't need the function declarations. (In fact I'm not sure that works at all.)

This line:

 var dictionary:NSMutableDictionary;

Does not create a mutable dictionary, you need to write:

var dictionary = NSMutableDictionary()
iluvcapra
  • 9,436
  • 2
  • 30
  • 32