仅在属性存在时测试它?(Test a property only if it exists?)

如果响应没有msgs[0]属性,则以下测试会生成错误。

if response.msgs[0] === "published" { ... }

错误是:

Uncaught TypeError: Cannot read property '0' of undefined

如何重写测试以生成错误? 如果没有msgs[0]属性,我希望测试评估为false


The following test generates an error if the response does not have a msgs[0] property.

if response.msgs[0] === "published" { ... }

The error is:

Uncaught TypeError: Cannot read property '0' of undefined

How can I rewrite the test to generate an error? If there is no msgs[0] property, I want the test to evaluate to false.


原文:https://stackoverflow.com/questions/37543272
2023-01-18 17:01

满意答案

你在哪里获得访问令牌fb添加后通知

[[NSNotificationCenter defaultCenter] postNotificationName:@“fbDidLogin”object:nil];

现在用于初始fb登录的方法是

-(void)fbLogin
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fbDidLogin) name:@"fbDidLogin" object:nil];
 // some logic for intial fb login page
 }

另外在fbDidLogin方法中添加这个

- (void)fbDidLogin 
{   
[[NSNotificationCenter defaultCenter]removeObserver:self name:@"fbDidLogin" object:nil]; 
[self.switch setOn:YES animated:YES];    
}

这里fbDIdLogin将在接收到令牌时立即被调用

如果访问令牌为零,则可以对fb登录失败执行类似的过程。


where u get access token for fb add post notification

[[NSNotificationCenter defaultCenter] postNotificationName:@"fbDidLogin" object:nil];

Now the method for intial fb login is

-(void)fbLogin
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fbDidLogin) name:@"fbDidLogin" object:nil];
 // some logic for intial fb login page
 }

Also in fbDidLogin method add this

- (void)fbDidLogin 
{   
[[NSNotificationCenter defaultCenter]removeObserver:self name:@"fbDidLogin" object:nil]; 
[self.switch setOn:YES animated:YES];    
}

Here fbDIdLogin will be called as soon as access token is recieved

Similar process can be done for fb login failed if access token is nil .

相关问答

更多

iPhone - 在Facebook登录后,UISwitch的状态未设置为“On” - (void)fbDidLogin方法(iPhone - After facebook login, status of UISwitch is not setting to 'On' in -(void)fbDidLogin method)

你在哪里获得访问令牌fb添加后通知 [[NSNotificationCenter defaultCenter] postNotificationName:@“fbDidLogin”object:nil]; 现在用于初始fb登录的方法是 -(void)fbLogin { [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fbDidLogin) name:@"fbDidLogin" object:nil];...

facebook fbDidLogin appdelegate外面(facebook fbDidLogin outside appdelegate)

您可以从App Delegate发布通知,如下所示: - (void)fbDidLogin { [[NSNotificationCenter defaultCenter] postNotificationName:@"FBDidLoginCalled" object:nil]; } 然后在你的其他课堂上: - (void)loginFacebook { if (![facebook isSessionValid]) { [[NSNotificationCente...

具有UISwitch功能的iPhone UIButton(iPhone UIButton with UISwitch functionality)

UIButton已经支持“切换”功能。 只需在Interface Builder中为“Selected State Configuration”选择不同的图像,并使用UIButton的selected属性来切换其状态。 UIButton already supports a "switch" functionality. Just set a different image in Interface Builder for the "Selected State Configuration", a...

Facebook在应用程序内执行(无需在Safari或本机应用程序中打开)(Facebook Implementation within app (without opening in safari or native app))

在Facebook iOS SDK中,您可以编辑Facebook.m的授权方法,并将safariAuth和authorizeWithFBAppAuth设置为no,以便它执行Facebook连接样式弹出式登录。 In the Facebook iOS SDK, you can edit Facebook.m's authorize method and set safariAuth and authorizeWithFBAppAuth both to no so that it does the F...

是否有可能在iPhone的设置中检测Facebook登录状态?(Is it possible to detect facebook log in status in iphone's settings?)

以下将告诉你。 它会提示用户许可,但只有在iOS设置中启用了Facebook的情况下。 查看返回的错误代码以区分不同的失败情况。 将“YOUR_FACEBOOK_APPID”替换为您的Facebook应用的ID。 ACAccountStore *accountStore = [[ACAccountStore alloc] init]; ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:AC...

UISwitch不返回其当前状态(开/关)(UISwitch not returning its current state (on/off))

用此代码替换代码。 并作为值更改控制事件再次与开关连接。 - (IBAction) sanitySwitch:(id)sender { if ([sender isOn]) { NSLog(@"SanityCheck ENABLED"); sanityCheck = YES; } else { NSLog(@"SanityCheck DISABLED"); sanityCheck = NO; } } ...

UISwitch无法正常工作(UISwitch is not working properly)

正如上面提到的@ILideTau,你不应该直接使用UISwitch状态,而只是创建一个Bool变量,它将保持你的开关状态,并在你更改didSet {}闭包中的状态时更新UI: @IBOutlet weak var interestedInSwitch: UISwitch! var interstedInState: Bool = false { didSet { interestedInSwitch.on = interstedInState } } func u...

向UISwitch添加行为(Add behaviour to UISwitch)

您只希望在调用setFrame:时更改frame属性。 尝试编写一个覆盖setFrame的UISwitch类:一个类将由所有子类继承,并且因为setFrame:是从UIView继承的,并且未在UISwitch中声明,所以可以覆盖setter。 这样的事可能 - // UISwitch+UISwitchAdditions.h #import <UIKit/UIKit.h> @interface UISwitch (UISwitchAdditions) - (void)setFrame:(CGRe...

Facebook iOS登录 - 未调用委托方法(Facebook iOS Login - Delegate methods not being called)

糟糕,我刚刚意识到application: handleOpenURL: method是一个iOS应用程序委托方法。 我在其中一个UIViewControllers中使用过它。 将它移动到正确的位置,它的工作原理。 Oops, I've just realized the application: handleOpenURL: method is an iOS application delegate method. I had it in one of my UIViewControllers....

iphone - 使用UISwitch(iphone - using a UISwitch)

我认为你应该按下自定义的“是”和“否”按钮。 通过这种方式,您可以更好地控制设计,并且可以避免Apple拒绝。 I think you should make custom "Yes" & "No" buttons that get selected when pushed. This way, you'll have more control on the design and you'll be safe from Apple rejection.

相关文章

更多

could not find system property or JNDI

Thanks everyone!! Finally got a solution for this p ...

mybatis There is no getter for property named 'xx' in 'class java.lang.String

用mybatis查询时,传入一个字符串传参数,且进行判断时,会报 There is no get ...

Hibernate 异常之:associate a collection with two ...

Hibernate exception - Illegal attempt to associate ...

[转]So You Want To Be A Producer

pro-du-cer n. 1. Someone from a game publisher who ...

Becoming a data scientist

Data Week: Becoming a data scientist Data Pointed, ...

Fading Like a Flower - Roxette

In a time 有一次 Where the sun descends alone, 太阳孤独的降落 ...

A Great List of Windows Tools

Windowsis an extremely effective and a an efficient ...

Drupal Forums instead of phpBB or vBulletin: A casestudy

5th Jan, 10 Drupal drupal advanced forum drupa ...

每日英语:Man Without a Country

'I'm like a proud son of China,' Taiwan-born direct ...

HTML 超链接(a标签、锚)

a标签: anchor锚 1.超链接 -&gt; 点击之后跳转页面 格式: 协 ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本