草庐IT

Failure-while

全部标签

swift - fatal error : unexpectedly found nil while unwrapping an Optional value when using AudioPlayer in Swift 2

您好,我正在尝试在swift2中使用以下代码播放音乐文件。基本上我只是将名为f.mp3的音频文件拖到asses文件夹中,我的代码中断并显示以下消息:在展开一个Optional值时意外地发现nil。我需要将mp3文件放在哪里,以便IOS可以找到它。谢谢varaudioPlayer:AVAudioPlayer!=nilfuncplayMyFile(){letpath=NSBundle.mainBundle().pathForResource("f",ofType:"mp3")letfileURL=NSURL(fileURLWithPath:path)do{tryaudioPlayer=AV

ios - HKHealthStore deleteObjects 报错 Domain=com.apple.healthkit Code=100 "Transaction failure."

我正在尝试使用HKHealthStoredeleteObjects一次删除大约400个对象并且我'我遇到了这个奇怪的错误。ErrorDomain=com.apple.healthkitCode=100"Transactionfailure."代码如下:self.healthKitStore.deleteObjects(deleteQ,withCompletion:{(success,error)->Voidin})有什么想法吗?谢谢! 最佳答案 有时,如果您在保存或删除示例之前没有requestAuthorizationToShar

ios - xcodebuild no such module 'SwiftyJSON' while build in xcode works

在我的项目中,我使用的是CocoaPods,podfile如下所示:defshared_podsuse_frameworks!pod'SwiftyJSON','~>3.1.4'pod'Alamofire','~>4.3.0'pod'PromiseKit','~>4.4'endtarget'myop'doshared_podsend通过xcode构建工作正常,但如果我尝试通过命令行(xcodebuild工具)构建,我会收到以下错误:error:nosuchmodule'SwiftyJSON'importSwiftyJSON我尝试重新安装SwiftyJSON并将其升级到新版本。还尝试手动将

iOS 8 核心数据堆栈 - fatal error : found nil while unwrapping an Optional value

我是iOS开发的新手,因此决定实现我自己的核心数据堆栈,以取代Apple的默认堆栈。我不得不对我的代码进行更改(很明显)并且已经能够弄清楚,但是在这种情况下我不能。这是我的代码:importUIKitimportCoreDataclassAddTableViewController:UITableViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate{@IBOutletweakvarnameTextField:UITextField!@IBOutletweakvarlocationTex

Swift SpriteKit : png image appears black while the game is being run. 我该如何解决这个问题?

我正在使用Xcode、Swift和SpriteKit制作游戏。我在photoshop中制作了一张涉及透明度的png图片,在游戏中显示为纯黑色。我还有其他png图像,它们也涉及透明度,它们以预期的方式出现。我不认为这是代码问题,但为了以防万一,这里是将图像引入游戏的代码(它在didMoveToView函数内):letwarning=SKSpriteNode(imageNamed:"yellow_warning")warning.setScale(0.1)warning.anchorPoint=CGPoint(x:0,y:0.5)warning.position=CGPoint(x:CGR

swift - 获取 clang : error: linker command failed with exit code 1 (use -v to see invocation) while google signing

我在不使用cocoapods的情况下链接Google登录时遇到此错误。我在这里提到了很多解决方案,但没有一个解决了我的问题。请指导我找到合适的解决方案。Undefinedsymbolsforarchitecturex86_64:"_GSDK_NSClassFromString",referencedfrom:l010inGoogleSignIn(GIDSignIn.o)l059inGoogleSignIn(GIDSignIn.o)"_OBJC_CLASS_$_GSDK_GTMOAuth2Authentication",referencedfrom:objc-class-refinGoo

swift - UICollectionView 问题 "fatal error: unexpectedly found nil while unwrapping an Optional value"

编辑:添加异常断点后(感谢大牛T),发现原来是我的cell.askingUsernameLabel.text=NSString(string:arr[indexPath.row])返回nil。这个问题的解决方案是在swift中,注册子类会覆盖你在Storyboard中所做的事情(如果使用Storyboard)。直接删除self.collectionView.registerClass(CollectionViewCell.self,forCellWithReuseIdentifier:"CollectionViewCell")一切顺利原创我真的迷失了这个:我试图在我的ViewContr

swift - Firebase 离线支持 : upload posts while user is offline and sync when user comes online in iOS Swift app

我在一个iOS-Swift项目中使用firebase,在这个项目中我必须为上传帖子启用离线支持,在帖子中有一张图片和标题就像Instagram,所以我想要的是当用户离线并且他/她想上传一个帖子,他/她的照片被保存在缓存中,当用户上线时,照片被上传并返回一个下载url,我们可以用它来保存帖子——在数据库中保存它的详细信息。示例代码是:letphotoIDString=UUID().uuidStringletstorageRef=Storage.storage().reference(forURL:"storagerefURL").child("posts").child(photoIDS

ios - 请求 caretRectForPosition : while the NSTextStorage has outstanding changes

我最近遇到错误:requestingcaretRectForPosition:whiletheNSTextStoragehasoustandingchanges{x,x}*“杰出”字面意思,不是我的错字。当我使用enumerateAttribute()方法遍历NSTextView子类的NSTextStorage并操纵NSTextAttachment在TextView中每次更改后的TextView中。funcmanipulateText(){lettext=customTextView.textStoragetext.enumerateAttribute(NSAttachmentAttr

swift - 如何在不使用 while 循环的情况下生成不包括一个的随机数?

假设我想生成一个介于1和100之间的随机数,但我不想包括42。如果不重复随机方法直到它不是42,我将如何做到这一点。 最佳答案 UpdatedforSwift5.1排除1个值varnums=[Int](1...100)nums.remove(at:42)letrandom=Int(arc4random_uniform(UInt32(nums.count)))print(nums[random])排除多个值Range的这个扩展在您想要排除超过1个值时确实提供了一种解决方案。extensionClosedRangewhereElemen