我很难找到/理解如何按照定义顺序比较Swift中的枚举的文档.特别是当我创建一个枚举如
enum EnumType {
case First, Second, Third
}
Run Code Online (Sandbox Code Playgroud)
Swift不允许我按顺序直接比较枚举,例如
let type1 = EnumType.First
let type2 = EnumType.Second
if type1 < type2 {println("good")} // error
Run Code Online (Sandbox Code Playgroud)
它生成编译错误"无法使用类型为{EnumType,EnumType}的参数列表调用'<'.所以我找到的唯一解决方案是将自己的比较运算符编写为重载,例如
enum EnumType : Int {
case First = 0, Second, Third
}
func <(a: EnumType, b: EnumType) -> Bool {
return a.rawValue < b.rawValue
}
let type1 = EnumType.First
let type2 = EnumType.Second
if type1 < type2 {println("good")} // Returns "good"
Run Code Online (Sandbox Code Playgroud)
对于在我的应用程序中有很多用途和价值的"重量级"枚举,这一切都很好,但是重载我可能想要使用的所有操作符对于我可能定义的"轻量级"枚举似乎过于繁琐为一个小模块带来一些常量的顺序.
如果没有为我在项目中定义的每个枚举类型编写大量的样板重载代码,有没有办法做到这一点?更好的是,是否有一些我缺少的东西使Swift自动为没有相关类型的简单枚举提供比较运算符,即.是无类型的还是输入为Int?Swift知道如何比较Ints,为什么不能比较enum Ints呢?
我是 Angular 的新手,在使用一直有效的服务时遇到了麻烦,直到它不起作用。我的服务有以下调用。
this.getForms = function() {
return $http.get("/forms").
then(function(response) {
return response;
}, function(response) {
alert("Error finding forms.");
});
};
Run Code Online (Sandbox Code Playgroud)
当刷新页面(safari)时,触发 getForms,调用 $http.get,我的 Node.js/Express 服务器表单端点正确返回表单数据。
app.get("/forms", function (req, res) {
Form.find({}, function (err, docs) {
if (err) {
server.handleError(res, err.message, "Failed to get forms.");
} else {
res.status(200).json(docs);
}
});
});
Run Code Online (Sandbox Code Playgroud)
但我得到的不是 JSON,而是 304 错误,这表明数据在缓存中可用。但 304 响应标头有一个空数据字符串,因此它不会从缓存返回任何数据。
我的问题是
1)如果数据在缓存中可用,为什么它会调用我的服务器?
2)我如何告诉它不缓存此调用,以便页面可以正确更新表单?
我正在尝试根据以下说明构建和运行入门React Native项目的iOS模拟器版本:
https://facebook.github.io/react-native/docs/getting-started.html
该应用程序在XCode模拟器中启动,非常简短地显示其窗口,但随后发生异常,并显示红色屏幕消息
“需要未知模块“ 498”。如果确定模块在那里,请尝试重新启动Metro Bundler。您可能还想运行
yarn或npm install(取决于您的环境)。loadModuleImplementation require.js:176:29
viewPropTypes.js:15:30
loadModuleImplementation require.js:212:12
View.js:20:22
loadModuleImplementation require.js:212:12
AppContainer.js:22:13“
等等
ViewPropTypes的第15行是
const PlatformViewPropTypes = require('PlatformViewPropTypes');
Run Code Online (Sandbox Code Playgroud)
node_modules / react_native / Libraries / Components / Views / View.js的第20行是
const ViewPropTypes = require('ViewPropTypes');
Run Code Online (Sandbox Code Playgroud)
注意:目录结构中还有另一个15行View.js文件,位于node_modules / react_native / lib /,它基本上是一个存根,包含
// This is a forwarding module to allow React to require React Native internals
// as node dependency
module.exports = require('View');
Run Code Online (Sandbox Code Playgroud)
我正在使用最新的MacOS High Sierra(10.13.4),已安装9.3命令行工具的XCode 9.3。我试过运行yarn和npm安装,以及全新安装。显然,我已经安装了NPM和Watchman。有什么想法为什么股票示例不会为我服务吗?