首页 \ 问答 \ 开关条件有布尔值?(switch condition has boolean value?)

开关条件有布尔值?(switch condition has boolean value?)

这段代码似乎完全合乎逻辑 为什么我得到“开关条件具有布尔值”错误? 我用它来切换UIButton上的文字。 它的工作原理,但我仍然有错误。

bool buttonSunStatus = TRUE;

- (void) useButtonSun:(id)sender
{
    buttonSun = [UIButton buttonWithType: UIButtonTypeCustom];
    switch (buttonSunStatus) {
        case TRUE:
            [sender setTitle:@"No Sun" forState:UIControlStateNormal];
            buttonSunStatus = FALSE;
            break;
        case FALSE:
            [sender setTitle:@"Sun" forState:UIControlStateNormal];
            buttonSunStatus = TRUE;
            break;
    }
}

This code seems perfectly logical. Why am I getting the "Switch condition has boolean value" error? I'm using it to switch the literals on a UIButton. It works but I still have the error.

bool buttonSunStatus = TRUE;

- (void) useButtonSun:(id)sender
{
    buttonSun = [UIButton buttonWithType: UIButtonTypeCustom];
    switch (buttonSunStatus) {
        case TRUE:
            [sender setTitle:@"No Sun" forState:UIControlStateNormal];
            buttonSunStatus = FALSE;
            break;
        case FALSE:
            [sender setTitle:@"Sun" forState:UIControlStateNormal];
            buttonSunStatus = TRUE;
            break;
    }
}

原文:https://stackoverflow.com/questions/26411482
更新时间:2022-03-10 12:03

最满意答案

我最终找到了使用karma-systemjs的解决方案。

在systemjs / files部分包含所有测试文件:

 systemjs: {
     files: [
         // TEST FILES
     ],

     configFile: 'system.config.js',

     config: {
         paths: {
             'angular-mocks': 'node_modules/angular-mocks/angular-mocks.js'
         }
     }
}

而在测试而不是使用:

System.import('boot');

使用:

'use strict';

import 'angular-mocks';
import 'angular/boot.js';

describe('Controller: B', function() {
    beforeEach(module('app'));

    var $scope;

    beforeEach(inject(function(_$rootScope_, $controller) {
        scope = _$rootScope_.$new();

        $controller('B', {$scope: $scope); 
    }));

    it('...', function() {

    });
});

希望这将有助于将来的其他人。


The solution I ended up finding involved using karma-systemjs.

Include all your tests files on the systemjs/files section:

 systemjs: {
     files: [
         // TEST FILES
     ],

     configFile: 'system.config.js',

     config: {
         paths: {
             'angular-mocks': 'node_modules/angular-mocks/angular-mocks.js'
         }
     }
}

And on the tests instead of using:

System.import('boot');

Use:

'use strict';

import 'angular-mocks';
import 'angular/boot.js';

describe('Controller: B', function() {
    beforeEach(module('app'));

    var $scope;

    beforeEach(inject(function(_$rootScope_, $controller) {
        scope = _$rootScope_.$new();

        $controller('B', {$scope: $scope); 
    }));

    it('...', function() {

    });
});

Hopefully this will help someone else in the future.

相关问答

更多
  • 我在Browserify和JSX上使用ES6。 编译我使用Babel。 以下配置适用于我。 karma.conf.js ... frameworks: ['browserify', 'jasmine'], files: [ 'Component.js', // replace with your component '__tests__/Component-test.js' ], preprocessors: { 'Component.js': 'brow ...
  • ES5没有承诺。 像jQuery或Angular这样的库有自己的定制和非标准的promise实现。 与ES5一起使用的受欢迎的Promise实现是Bluebird(它与ES6标准兼容)和Q(它最初并不与ES6标准兼容 - 尽管似乎正在朝着这个方向发展)和RSVP。 也不是真正的polyfills,因为如果有本地承诺存在,它们不会妨碍它们,因为它们增加了额外的功能。 ES6承诺有一些纯粹的polyfills。 以下是RSVP的一个子集: https : //github.com/stefanpenner/es ...
  • 您在测试中包含已转换的文件。 例如,在错误中查看此行: WARNING in ./~/routes/dist/routes.js Critical dependencies: 1:406-413 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results. @ ./~/r ...
  • 我实际上建议采用略有不同的测试方法。 如果目标是测试SideNavController中的逻辑,我会考虑将该类移动到它自己的文件中。 这样你就可以在指令和测试中导入它。 以这种方式构建它可以让您更容易地访问它,因为您可以完全独立于指令本身进行测试。 通过编译标记和创建整个指令来测试它基本上将其转换为集成测试,并且管理起来有点复杂。 一般来说,我发现这可以提供更多可维护和有用的测试 - 特别是如果目标是测试控制器。 它与我的例子类似: http : //www.syntaxsuccess.com/viewar ...
  • 角度constant服务只是一种在配置阶段可用的服务,是存储模块常量的建议方式(因此名称)。 它不是一个真正的常量,可以随时用$provide.constant覆盖。 链式angular.module(...)导出Module对象 ,在非Angular上下文中没有意义。 为Angular模块和ES6模块保留单独的导出。 导出Angular模块name属性是一种常规方法,该属性可以在语义上导入并在其他模块中使用。 export const foo = ...; export default angular. ...
  • 我最终找到了使用karma-systemjs的解决方案。 在systemjs / files部分包含所有测试文件: systemjs: { files: [ // TEST FILES ], configFile: 'system.config.js', config: { paths: { 'angular-mocks': 'node_modules/angular-mocks/angular-mo ...
  • 使用TS可能会更容易升级到Angular(2+)。 除此之外,特别是使用ES6 / TS而不是VanillaJS的Vanilla JS没有特别的好处。 与Vanilla JS相比,使用ES6 / TS有一般的好处(和权衡)。 将不会遇到AngularJS特定的问题,而使用TS / ES将使组织代码,代码可理解性等的生活更容易..如此处和此处所述。 Using TS will probably make it easier to upgrade to Angular (2+). Other than that ...
  • 您需要在组件 类 函数上使用静态属性annotations和parameters ,如下所示: function Service() {} function AppComponent(service) { console.log(service); } AppComponent.prototype.ngOnInit = function() { console.log('test ngOnInit'); }; AppComponent.annotations = [ new Compone ...
  • super($rootScope, $state, $log); 调用父构造函数。 你有 this.activate(); 由于this是ConversationDetailController一个实例,因此调用其activate方法,而不是ConversationListController 。 你有 let id = this.$stateParams.id; 但$stateParams尚未设置,因为: super($rootScope, $state, $log); <- You are her ...
  • $scope.Contact.title = $scope.doctitles[$scope.doctitles.findIndex(function(x) { return x.id == $localStorage.data.contacts[$localStorage.data.itemID].title.id; })]; 您只需用函数替换lambda即可。 编辑:由于findIndex也是ES6,你可以使用这个polyfill: if (!Array.prototype.findIndex ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。