我試圖做一個應用程序,你在一定數量的時間點按下按鈕儘可能多次。我一直在構建它,並在過去的一週左右每天在我的iPhone上運行它,但是現在突然間Xcode正在給我提供錯誤和「錯誤分段11」。我刪除了添加的代碼,從故事板中刪除了某些內容,甚至重新安裝了Xcode,但沒有任何方法可以解決問題。有關於如何解決這些問題的文章和視頻,但他們中沒有一個似乎對我有用。分段錯誤11修復?
這裏是我的代碼:
import UIKit
import Foundation
import AudioToolbox
// PlaySounds
class PlaySounds {
private var soundID: SystemSoundID = 0
public init(named name: String) {
if let soundURL = soundURL(forName: name) {
let status = AudioServicesCreateSystemSoundID(soundURL as CFURL, &soundID)
if status != noErr {
print("Unable to create sound at URL: '\(name)'")
soundID = 0
}
}
}
public func play() {
if soundID != 0 {
AudioServicesPlaySystemSound(soundID)
}
}
private func soundURL(forName name: String) -> URL? {
let fileExtensions = ["m4a", "wav", "mp3", "aac", "adts", "aif", "aiff", "aifc", "caf", "mp4"]
for fileExtention in fileExtensions {
if let soundURL = Bundle.main.url(forResource: name, withExtension: fileExtention) {
return soundURL
}
}
print("Unable to find sound file with name '\(name)'")
return nil
}
deinit {
if soundID != 0 {
AudioServicesDisposeSystemSoundID(soundID)
}
}
}
// ViewController
class ViewController: UIViewController {
let startTimer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector(UIMenuController.update), userInfo: nil, repeats: true)
let XDSound = PlaySounds(named: "XDDDDDDD")
@IBAction func playButtonPressed(_ sender: AnyObject) {
XDSound.play()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
和錯誤代碼:
CompileSwift normal arm64 /Users/aaa/Desktop/XD/XD/XD/ViewController.swift
cd /Users/aaa/Desktop/XD/XD
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/aaa/Desktop/XD/XD/XD/ViewController.swift /Users/aaa/Desktop/XD/XD/XD/AppDelegate.swift -target arm64-apple-ios10.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk -I /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos -F /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos -enable-testing -g -module-cache-path /Users/aaa/Library/Developer/Xcode/DerivedData/ModuleCache -D DEBUG -serialize-debugging-options -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-generated-files.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-own-target-headers.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-all-target-headers.hmap -Xcc -iquote -Xcc /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-project-headers.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos/include -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/DerivedSources/arm64 -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/aaa/Desktop/XD/XD -emit-module-doc-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name XD -emit-module-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.d -emit-reference-dependencies-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.swiftdeps -o /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.o
0 swift 0x000000010bf6bb6d PrintStackTraceSignalHandler(void*) + 45
1 swift 0x000000010bf6b5b6 SignalHandler(int) + 470
2 libsystem_platform.dylib 0x00007fffa9fdebba _sigtramp + 26
3 libsystem_platform.dylib 0x00007fff568ee500 _sigtramp + 2895182176
4 swift 0x000000010944b00f llvm::Value* llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>::callback_fn<getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t)::$_3>(long, swift::irgen::IRGenFunction&, llvm::Constant*) + 255
5 swift 0x000000010944974a swift::irgen::emitLazyCacheAccessFunction(swift::irgen::IRGenModule&, llvm::Function*, llvm::GlobalVariable*, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&)> const&) + 1194
6 swift 0x000000010944b2cc getTypeMetadataAccessFunction(swift::irgen::IRGenModule&, swift::CanType, swift::ForDefinition_t, llvm::function_ref<llvm::Value* (swift::irgen::IRGenFunction&, llvm::Constant*)>&&) + 300
7 swift 0x000000010944ae45 emitCallToTypeMetadataAccessFunction(swift::irgen::IRGenFunction&, swift::CanType, swift::ForDefinition_t) + 117
8 swift 0x00000001094498dc swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType) + 108
9 swift 0x000000010948707d void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::EmitPolymorphicArguments::emit(swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::Substitution>, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&)::$_14>(long, swift::irgen::GenericRequirement) + 861
10 swift 0x000000010947c9e1 (anonymous namespace)::PolymorphicConvention::enumerateRequirements(llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 129
11 swift 0x0000000109486bdb swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::Substitution>, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&) + 459
12 swift 0x00000001094e34f5 (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 2997
13 swift 0x00000001094ce268 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9080
14 swift 0x00000001093f2601 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1329
15 swift 0x00000001094b3fcb performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1259
16 swift 0x00000001093821c7 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23687
17 swift 0x000000010937a265 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
18 swift 0x000000010933782d main + 8685
19 libdyld.dylib 0x00007fffa9dd2255 start + 1
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/aaa/Desktop/XD/XD/XD/ViewController.swift /Users/aaa/Desktop/XD/XD/XD/AppDelegate.swift -target arm64-apple-ios10.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk -I /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos -F /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos -enable-testing -g -module-cache-path /Users/aaa/Library/Developer/Xcode/DerivedData/ModuleCache -D DEBUG -serialize-debugging-options -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-generated-files.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-own-target-headers.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-all-target-headers.hmap -Xcc -iquote -Xcc /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/XD-project-headers.hmap -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Products/Debug-iphoneos/include -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/DerivedSources/arm64 -Xcc -I/Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/aaa/Desktop/XD/XD -emit-module-doc-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController~partial.swiftdoc -Onone -module-name XD -emit-module-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.dia -emit-dependencies-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.d -emit-reference-dependencies-path /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.swiftdeps -o /Users/aaa/Library/Developer/Xcode/DerivedData/XD-glogqttrbkyynngrdofevqkflfyf/Build/Intermediates/XD.build/Debug-iphoneos/XD.build/Objects-normal/arm64/ViewController.o
1. While emitting IR SIL function @_TFC2XD14ViewControllercfT7nibNameGSqSS_6bundleGSqCSo6Bundle__S0_ for 'init' at /Users/aaa/Desktop/XD/XD/XD/ViewController.swift:56:40
它說的錯誤 「(SWIFT):56:40」 的底部,我認爲指的第40個字符第56行,但所有這些都是ViewController的左括號。幫幫我?
我把你的代碼粘貼到Xcode 8的遊樂場中,並立即得到這個錯誤:「LLDB RPC服務器崩潰了。崩潰日誌位於〜/ Library/Logs/DiagnosticReports中,並有一個前綴'lldb-roc-server'。請提交一個錯誤並附上最新的崩潰日誌。「因此,看起來你發現了一個LLDB調試器的錯誤! –