Tag: 致命错误

将iOS Core Data添加到现有项目 – 解包可选值时发生错误

我试图将CoreData添加到现有的项目。 所以,我复制了一个新项目的数据模型(SWS.xcdatamodel)和AppDelegate文件。 然后我改变了AppDelegate方法中的项目名称和数据模型名称 import UIKit import CoreData @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. return true } func applicationWillResignActive(application: UIApplication) { // Sent when the application is about to move from active to inactive state. […]

Swift 2 – 调用`didDeselectItemAtIndexPath`时发生致命错误

我有一个UICollectionView我使用函数didSelectItemAtIndexPathselect一个单元格,并更改其alpha。 在UICollectionView有12个单元格。 为了将取消选中的单元格返回到alpha = 1.0我使用函数didDeselectItemAtIndexPath 。 到目前为止,代码工作,但是,当我select一个单元格,并滚动UICollectionView应用程序崩溃在线let colorCell : UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)! 里面的错误取消selectfunction: 致命错误:意外地发现零,而解包一个可选的值(lldb) 我想我需要重新加载收集视图,但如何重新加载并保持单元格select? override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) { let colorCell : UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)! colorCell.alpha = 0.4 } override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) { let colorCell : UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)! colorCell.alpha = 1.0 }

AVAudioPlayer在模拟器上工作,但不在真实设备上

当我播放录制的audio时,我得到这个错误: 致命错误:意外地发现零,而解包一个可选值 在这行代码中: SoundPlayer = try AVAudioPlayer(contentsOfURL: getFileURL()) 但是,除了真实的设备之外,它在模拟器上是完美的。 ViewController.Swift: import UIKit import AVFoundation class ViewController: UIViewController, AVAudioPlayerDelegate, AVAudioRecorderDelegate { @IBOutlet var PlayBTN: UIButton! @IBOutlet var RecordBTN: UIButton! var soundRecorder : AVAudioRecorder! var SoundPlayer : AVAudioPlayer! var fileName = "audioFile.m4a" override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically […]

从parse.com检索数据时出错

你好,我想从我的parse.com类中获取一些名为“Tags”的数据,这个类有两个3 cols“objectID”,“username”和“tagtext”。 我想通过ID和后缀来读取logging查找,并将“useername”和“tagtext”保存为两个string。 我已经像parse.com文档中那样做了: @IBAction func readAction(sender: UIButton) { var query = PFQuery(className:"Tags") query.getObjectInBackgroundWithId("IsRTwW1dHY") { (gameScore: PFObject?, error: NSError?) -> Void in if error == nil && gameScore != nil { println(gameScore) } else { println(error) } } let username = gameScore["username"] as! String let tagtext = gameScore["tagtext"] as! String println(username) println(tagtext) } 我得到一个错误,称为fatal error: […]

swift可以捕获致命错误?

我正在尝试使用Swift 2.0 try-catch。 我原来有以下代码 override func viewDidLoad() { var obj : Object?; Hi( obj ); } 但它造成了一个错误 func Hi( open : Open? ) -> Open? { open!.Hi(); <– here is error point. Fatal error ! print( "OK" ); return open; } 因此,我将viewDidLoad()中的代码更改为: override func viewDidLoad() { try { var obj : Object?; Hi( obj ); […]