B-Sides / ELCImagePickerController

A clone of the UIImagePickerController using the Assets Library Framework allowing for multiple asset selection
http://www.icodeblog.com
1.65k stars 469 forks source link

It crashes on Xcode8 & Swift 3.0. #135

Open showmylym opened 8 years ago

showmylym commented 8 years ago

The crash position stopped at @UIApplicationMain, and printed following log in console.

invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.
libc++abi.dylib: terminate_handler unexpectedly threw an exception

Present code is

                        let imagePicker = ELCImagePickerController(imagePicker: ())
                        imagePicker?.mediaTypes = [ALAssetTypePhoto]
                        imagePicker?.onOrder = true
                        imagePicker?.maximumImagesCount = canSelectPhotoNum
                        imagePicker?.imagePickerDelegate = self
                        imagePicker?.navigationBar.barTintColor = ColorMainTheme
                        imagePicker?.navigationBar.tintColor = UIColor.white
                        imagePicker?.navigationBar.titleTextAttributes = [NSFontAttributeName: self.titleLabel.font, NSForegroundColorAttributeName: imagePicker?.navigationBar.tintColor]
                        imagePicker?.navigationItem.title = StrPhoto
                        self.present(imagePicker!, animated: true, completion: nil)
showmylym commented 8 years ago

Oh, I got it. The reason of crash is that imagePicker?.navigationBar.titleTextAttributes = [NSFontAttributeName: self.titleLabel.font, NSForegroundColorAttributeName: imagePicker?.navigationBar.tintColor] type of titleTextAttributes is [String: Any]?,so that self.titleLabel.font and imagePicker?.navigationBar.tintColor can't be optional type. It won't be crash if force unwrap optional value before use it.