草庐IT

ios - Swift ios - 将 key=value 文本文件读入 nsdictionary

我有各种文本文件,其中每一行都包含string-key=string-value我可以将文件读入字符串(或者可能是一个数组),逐行检查并自己拆分成键/值对,但是,我想知道我是否缺少一些内置或更简单的“快速”方式这样做(swift的新手)我找不到之前讨论过的这个问题 最佳答案 核心概念仍然依赖于componentsSeparatedByString,但您可以通过使用像reduce这样的高阶函数让它看起来更“敏捷”:letfileContent=try!NSString(contentsOfFile:"/path/to/file.txt

ios - 错误说 "value of type ' FIRDatabaseReference' 没有成员 'observe'“

这是我遇到错误的行:databaseHandle=ref.child("Posts").observe(.childAdded,withBlock:{(snapshot)inself.postData.append("")})下面是所有的代码...importUIKitimportFirebaseDatabaseclassFirstViewController:UIViewController,UITableViewDelegate,UITableViewDataSource{@IBOutletvartableView:UITableView!varref:FIRDatabaseRef

ios - 从其他 Observable 获取值(value)的 Rx Observable

我是RxSwift和MVVM的新手。我的viewModel有一个名为rx_fetchItems(for:)的方法完成从后端获取相关内容的繁重工作,并返回Observable.我的目标是提供名为collectionItems的viewModel的可观察属性,最后发出的元素从rx_fetchItems(for:)返回,为我的collectionView提供数据。DanielT提供了我可能会使用的解决方案:protocolServerAPI{funcrx_fetchItems(forcategory:ItemCategory)->Observable}structViewModel{letc

swift - databaseReference.observe(DataEventType.value, :{(DataSnapshot) not working properly all the time

funccheckPaid(utilityId:String)->Int{varamount:String=""varstatus=0print("insidenewfunction")print("\(utilityId)insidenewfunction")self.databaseRefPayment.observe(DataEventType.value,with:{(DataSnapshot)inifDataSnapshot.childrenCount>0{forpaymentsinDataSnapshot.children.allObjectsas![DataSnapsho

ios - Firebase 的 snapshot.value 转换为 Bool 突然返回 nil

所以我的代码运行得非常好,但今天当我尝试将Firebase的snapshot.value转换为Bool时它返回nil。我根本没有对代码进行任何更改。但是,如果我将它转换为一个字符串,它就可以正常工作(因为?字符串返回“true”)。在我转换为[String:Bool]的另一个地方出现了同样的问题。与之前不同的是,我今天安装了Xcode10beta3(也安装了Xcode9.4)。两个Xcode版本都返回nil。这是代码:ifletcurrentUserId=Auth.auth().currentUser?.uid{Database.database().reference().child

ios - Swift 4 : Variable 'value' inferred to have type 'Void' , 这可能是意想不到的?

我正在尝试将存储在firebase存储中的图像的下载URL保存在数据库中。我看过here,和here,但是我收到以下错误:Cannotconvertvalueoftype'Void'totype'[String:String]'incoercion这发生在下面指示的行上:storageRef.downloadURL{(url,error)inguardletdownloadURL=urlelse{//Uh-oh,anerroroccurred!return}//databaseintegrationletref=Database.database().reference()letuse

swift - 从 Firebase Firestore - Swift 4 获取当前用户的值(value)

这是我的第一个问题,希望你能帮助我。我一直在尝试获取当前用户登录我的应用程序的特定路径。我现在真的不知道我做错了什么,所以我会在这里粘贴我的代码。funcuserRoleListener(){guardletuser=Auth.auth().currentUserelse{return}.Firestore.firestore().collection("users").document("sjbD5SvKTYHWBLhCqojs").getDocument{(snapshot,error)inifletdata=snapshot?.data(){guardletisAdmin=dat

uitableview - swift - 错误 : unexpectedly found nil while unwrapping an optional value

我一直在用Swift制作应用程序,但我的TableViewController类中一直出现错误。我找不到任何方法来解决此问题并不断收到此错误:overridefunctableView(tableView:UITableView?,cellForRowAtIndexPathindexPath:NSIndexPath!)->UITableViewCell!{letcell:TextTableViewCell=tableView!.dequeueReusableCellWithIdentifier("Cell",forIndexPath:indexPath!)asTextTableView

swift - 从 Parse.com 检索 PFFile 时为 "unexpectedly found nil while unwrapping an Optional value"

我在检索存储在Parse.com中的PFFile时遇到问题letuser=PFUser.currentUser()letuserImageFile=user["profileImage"]asPFFileuserImageFile.getDataInBackgroundWithBlock{(imageData:NSData!,error:NSError!)->Voidiniferror==nil{ifimageData!=nil{letimage=UIImage(data:imageData)self.profileImage.image=image}}}错误从第二行开始。“profi

ios - 在 Swift ios 中使用 vImageBuffer_initWithCGImage 时出现 "fatal error: unexpectedly found nil while unwrapping an Optional value"

我正在使用SwiftiOS8并尝试将UIImage转换为vImage_Buffer以使用Accelerate.framework执行操作。我正在尝试使用vImageBuffer_initWithCGImage进行转换,这是我尝试过的代码:funcinitvImageBufferwithUIImage(image:UIImage)->vImage_Buffer{varCGImg:CGImageRef=sunset.CGImagevarinProvider:CGDataProviderRef=CGImageGetDataProvider(CGImg)varinBitmapData:CFDa