2015-03-08 37 views
2

这是改变振动的长度GBA4iOS控制器视图采取几乎一字不差的几行代码:这里如何将这个Objective-C代码片段写入Swift?

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 

我尝试只是拒绝在任何情况下工作:

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); 
} 

当未注释时,它会崩溃SourceKit,但只在视图控制器中。当我把它放在自己的文件:

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

我试着尽我所能,如果你能帮助它将会是极大的赞赏

回答

0

你的“AudioServicesPlaySystemSoundWithVibration”声明后删除组括号。

来源:

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

要:

func AudioServicesPlaySystemSoundWithVibration(Int , NilLiteralConvertible, NSDictionary); 
0

首先,你并不需要的函数声明。 (其实我不知道,在所有的作品。)

这条线:

var dictionary:NSMutableDictionary; 

不创建一个可变的字典,你需要写:

var dictionary = NSMutableDictionary() 
相关问题