我需要让iPhone振动,但我不知道如何在Swift中做到这一点.我知道在Objective-C中,你只需写:
import AudioToolbox
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
Run Code Online (Sandbox Code Playgroud)
但那不适合我.
我正在Swift中编写一个iOS游戏,我想在最后添加一个高分标签.我认为保存功能是正确的,但负载一是给我带来问题的.我已经创建了一个实体("BestScores")和属性("classicBestScoreTF"):
要保存高分:
var bestscore25 = 1000
var score: int
func savescore() {
var appDel: AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
var context:NSManagedObjectContext = appDel.managedObjectContext!
var score25: AnyObject! = NSEntityDescription.insertNewObjectForEntityForName("BestScores", inManagedObjectContext: context) as NSManagedObject
score25.setValue(score, forKey: "classicBestScoreTF")
context.save(nil)
}
func loadscore() {
var appDel: AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
var context:NSManagedObjectContext = appDel.managedObjectContext!
bestScore25 = valueForKey("classicBestScoreTF") as Int
}
func endgame() {
if score > bestScore25 {
savescore()
loadscore()
bestScoreLabel.text = "Best Score: \(bestScore25)"
}
if score < bestscore {
loadscore()
bestScoreLabel.text …Run Code Online (Sandbox Code Playgroud)