首页 \ 问答 \ 是否可以安全地使用切换FlowType联合类型(String Enums)?(Is it possible to safely use Switch over FlowType union types (String Enums)?)

是否可以安全地使用切换FlowType联合类型(String Enums)?(Is it possible to safely use Switch over FlowType union types (String Enums)?)

在以下示例中,由于我使用switch语句使用匹配的消息类型,因此我希望流程能够识别“ENUM_TYPO”的不正确情况。 目前没有。

type Message = 'BROADCAST_MESSAGE' | 'PRIVATE_MESSAGE';

const message: Message = 'BROADCAST_MESSAGE';

switch (message) {
  case 'ENUM_TYPO':
    // Do Broadcast
    break;
  default:
    break;
}

In the following example, since I'm using matching over type of Message using the switch statement, I would like flow to recognise my incorrect case of 'ENUM_TYPO'. It currently doesn't.

type Message = 'BROADCAST_MESSAGE' | 'PRIVATE_MESSAGE';

const message: Message = 'BROADCAST_MESSAGE';

switch (message) {
  case 'ENUM_TYPO':
    // Do Broadcast
    break;
  default:
    break;
}

原文:https://stackoverflow.com/questions/39614908
更新时间:2023-02-03 22:02

最满意答案

您必须传递对NSError对象的引用NSError将执行该过程,如果有任何错误,它将更新错误对象并出现相应的错误。

你的新代码应该是这样的

-(BOOL)registerUser{
    NSError *error = nil;
    PFUser *newUser = [PFUser user];
    newUser.username = self.username;
    newUser.password = self.password;
    [newUser signUp:&error]; // error

    if( error != nil)
    {
      //log the error or show alert
      return NO;
    }

    return YES;


}

You have to pass a reference to a NSError object.. Parse will do the process and if any error is there it will update the error object with appropriate error.

You new code should be like

-(BOOL)registerUser{
    NSError *error = nil;
    PFUser *newUser = [PFUser user];
    newUser.username = self.username;
    newUser.password = self.password;
    [newUser signUp:&error]; // error

    if( error != nil)
    {
      //log the error or show alert
      return NO;
    }

    return YES;


}

相关问答

更多
  • 您必须传递对NSError对象的引用NSError将执行该过程,如果有任何错误,它将更新错误对象并出现相应的错误。 你的新代码应该是这样的 -(BOOL)registerUser{ NSError *error = nil; PFUser *newUser = [PFUser user]; newUser.username = self.username; newUser.password = self.password; [newUser signUp:&error ...
  • 注 - 此答案不使用标准PFUser类别。 基本上它不起作用。 如果您没有使用实际的PFUser类,Parse中的任何内容都不起作用(例如,电子邮件验证,密码重置,帐户处理,等等) 使用PFUser添加额外字段非常简单:(1)以正常方式创建用户。 (2) 在单独的电话中 ,发送其他字段。 通常你也会有一个图像(如用户头像) - 在另一个cal中单独发送。 在经过大量的研究后,我发现这是我问题的解决方案。 我在这里分享它,这样对其他人也有用 -(void)userSignUp:(NSDictionary*)u ...
  • 自从提出这个问题以来,我们已经制定了一个计划。 任何反馈都将非常感激。 我们计划做的是:(a)将我们的sqlite数据库迁移到解析本地数据存储区(引脚)。 我们不会使用saveEventually ,而是使用pinInBackground: ,将所有对象固定到特定组并将标志isDraft (或类似的东西)设置为true。 然后,此标志允许我们访问仍需要同步到parse.com的那些对象。 然后,当应用程序关闭时,我们将启动应用程序中的后台任务,从该组中拉出仍然是草稿的固定对象,将其isDraft标志设置为f ...
  • 使用小写s进行函数声明和调用start。 同样值得注意的是你应该说出一些东西,所以很清楚它是什么。 @IBAction func signUpButton(sender: AnyObject) { signUp() // Calling signUp function here that is declared below. } func signUp(){ // Do sign up stuff. } Make the function declaration and call sta ...
  • 您提到用户应该能够在注册后编辑他们的个人资料。 使用signUpInBackgroundWithBlock向Parse注册用户时,Parse SDK将自动为您创建一个PFUser 。 在您提供的代码中,您正在创建并保存一个全新的PFUser而不是获取当前登录的PFUser 。如果您未使用已登录的PFUser ,那么您将在user.saveInBackgroundWithBlock (您在你的文章中也提到): User cannot be saved unless they are already signe ...
  • 事实证明,您可以通过将Parse PHP会话令牌传递给Javascript API来执行此操作,如下所示: getSessionToken(); echo 'var token="'.$sessionToken.'";'; ?> Parse.User.become(token).then(function (user) { // Th ...
  • 通过检查Parse JS sdk文档,在调用注册函数时似乎错过了一个参数: user.signUp(null, { success: function(user) { // Hooray! Let them use the app now. }, error: function(user, error) { // Show the error message somewhere and let the user try again. alert("Error: " + e ...
  • Parse.com正在关闭,这就是为什么不允许您在服务上创建新帐户的原因。 查看博客文章 。 他们开源了一个nodeJS实现,你肯定应该在链接上查看,这是一个让你入门的例子 。 您可以轻松使用部署按钮在Heroku,AWS,Azure等服务上托管服务器。您还可以在本地部署服务器以进行测试。 Parse.com is shutting down, so that's why you are not allowed to create new accounts on the service. Check the ...
  • 您应该将succeeded值的类型更改为ObjCBool 。 PFBooleanResultBlock的签名现在改变了(Bool, NSError?) -> Void to (ObjCBool, NSError?) -> Void 所以你应该将Bool类型更改为ObjCBool ,如下所示: user.signUpInBackgroundWithBlock { (succeeded: ObjCBool, error: NSError?) -> Void in print(succeeded) ...
  • 您可以使用User类中的afterSave挂钩中的一个邮件云模块来实现此目的: Parse.Cloud.afterSave(Parse.User, function(request) { ... if user just signed up, email them ... }); You can implement this by using one of the mail Cloud Modules from an afterSave hook on the User class: Parse.Cloud ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)