草庐IT

re-doing-it-wrong

全部标签

swift/火力地堡 : How do I properly store a Facebook user into Firebase database when they create an account?

我正在尝试将用户保存到我的firebase数据库中。我正在使用FBSDKLoginManager()创建帐户/登录。创建帐户后,我想将用户存储到我的firebase数据库中。我目前可以让用户登录并且他们的电子邮件显示在firebase的Auth选项卡中(参见屏幕截图),但我的updateChildValues似乎没有任何影响(另请参见屏幕截图)。我是否将updateChildValues放在了正确的位置?它目前位于signInWithCredential中。我还必须执行FBSDKGraphRequest以获取我有兴趣存储在我的firebase数据库中的信息。我的firebase的Aut

ios - 在 Swift 中使用 block 给出错误 "Variable used within its own initial value"

这是我在obj-c中的代码:__blockNSString*requestReference=[selfoperation:methodurl:urlparameters:parametersheaders:headerssuccess:^(NSURLSessionDataTask*task,idresponseObject){NSError*error=[NSErrorerrorWithSessionTask:taskresponseObject:responseObject];if(error){NSLog(@"error-%@",error);[delegaterequestWi

swift - NSCopying 副本(带有 :) - Does it really need to return Any?

有没有什么方法可以使用NSCopying而返回的对象不是Any类型?它总是迫使我施法。这似乎很奇怪。我正在复制对象,Swift难道不应该根据copy这个词的定义知道它是同一类型吗?是否有另一种方法来复制我不知道的对象,或者是否有一些我缺少的“陷阱”需要这个。这个类很简单,比如:classPerson{varname:Stringvarage:Int}它必须是一个类,因为我需要继承。例子:varjohn=Person(name:"John",age:30)varjohnsClone=john.copy()as!Person我想我可以创建一个接受现有对象的初始化程序,但这在语义上似乎不如“

ios - 开关错误 : Expected member name or constructor call - what's wrong?

我想对我的3个案例进行切换,但我遇到了无法解决的错误:错误:在类型名称之后需要成员名称或构造函数调用自从我一直在使用类似的代码以来,一定有什么地方被我忽略了。但是现在我的项目几乎是空的,无法弄清楚出了什么问题?importUIKitclassViewController:UIViewController{enumMyStateStatus{caseReadycaseRunningcaseStopped}@IBActionfuncactionPressed(sender:UIButton){switchMyStateStatus{caseMyStateStatus.Ready:print

swift 3 (SpriteKit) : Locking the x axis of a SKSpriteNode and its physicsBody

我真的需要知道如何锁定SKSpriteNode及其physicsBody的x轴。我需要保持SKSpriteNodedynamic和affectedByGravity。该节点位于斜坡上,因此这就是它的x轴因重力而移动的原因。但是,我不希望此SKSpriteNode的x轴因重力而移动。有没有办法锁定x轴以实现此目的?感谢您的帮助:D编辑:我试过像这样对x值应用约束:letxConstraint=SKConstraint.positionX(SKRange(constantValue:195))node.constraints?.append(xConstraint)但是这不起作用,我不确定

swift : Enum 'cannot be constructed because it has no accessible initializers'

我很快就得到了这个错误'BlockColor'cannotbeconstructedbecauseithasnoaccessibleinitializersimportFoundationimportSpriteKitletNumberOfColors:UInt32=6enumBlockColor:Int,Printable{caseBlue=0,Orange,Purple,Red,Teal,YellowvarspriteName:String{switchself{case.Blue:return"blue"case.Orange:return"orange"case.Purple:

ios - Realm swift : Is it possible to keep database after the apps is uninstalled?

使用realmswift,是否可以在应用程序从设备上卸载后在设备内存中保留和维护应用程序的Realm数据库文件?非常感谢您的帮助。 最佳答案 遗憾的是没有。这是iOS的限制,而不是Realm的限制。当从设备上卸载iOS应用程序时,所有与其关联的文件(包括任何Realm文件)都会被删除。如果您希望文件数据在应用程序被删除后仍然存在,您需要查看云托管解决方案以保留这些文件的副本。在这种情况下,最简单的很可能是CloudKit. 关于ios-Realmswift:Isitpossibletok

ios swift : Is it possible to change the font style of a certain word in a string?

我正在从数据库中提取字符串形式的内容。我用一种方法从这个字符串中提取最长的单词。现在我想将整个字符串打印到文本标签中,但想以不同的颜色和文本样式突出显示字符串中最长的单词。我该怎么做?我是否需要将字符串切成小块-设置格式-并在将其提供给标签之前将它们重新组合在一起?或者还有其他(更好)的方法吗? 最佳答案 如果您已经知道最长的单词,则必须获取该单词在字符串中的范围。为此,我更喜欢NSString方法rangeOfString:。然后您使用您的默认属性从字符串创建一个NSMutableAttributedString。最后,您将突出显

swift 2.0 : Parametrized classes don't call proper == function if it inherits from class that is Equatable

当参数化类继承自另一个符合Equatable的类时,==调用父类(superclass)的==。谁能解释为什么会这样和/或我怎么可能在这里做错了什么?我相信一个例子最能说明我的问题:publicclassFoo:Equatable{}publicfunc==(lhs:Foo,rhs:Foo)->Bool{returnfalse}//ParametrizedpublicclassBar:Foo{publicvarbar:T?publicinit(barIn:T?){self.bar=barIn}}publicfunc==(lhs:Bar,rhs:Bar)->Bool{returnlhs.

ios - Swift3 Xcode 8 : 'none' is unavailable: use [] to construct an empty option set ; What should I do?

我在ViewController.swift上使用Swift3中的UIUserNotificationType.none,我得到了这个错误:'none'isunavailableuser[]toconstructanemptyoptionset;这是我的代码:funcupdateUI(){letcurrentSettings=UIApplication.shared.currentUserNotificationSettingsifcurrentSettings?.types!=nil{ifcurrentSettings!.types==[UIUserNotificationType.