- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如何在 Swift 中放置一个静态 block ,就像在 Java 中一样?我试过 static var block = {}
但这行不通。它必须专门调用。
我想要的就像在 Java 中一样,静态大括号内的整个 block 在类初始化时执行。 Swift 中有类似的东西。我在整个互联网上搜索过,没有人有答案!类似的功能或解决方法也可以。
public class EnumRingLevel
{
public static final EnumRingLevel DEFAULT = new EnumRingLevel(
0, 0, "DEFAULT", 1000, 2000);
public static final EnumRingLevel SILENT = new EnumRingLevel(
10, 1, "SILENT", 1001, 2001);
public static final EnumRingLevel QUIET_BEEP = new EnumRingLevel(
20, 2, "QUIET_BEEP", 1002, 2002);
public static final EnumRingLevel NORMAL_BEEP = new EnumRingLevel(
30, 3, "NORMAL_BEEP",1003, 2003);
private final int gdbval;
private final int gindex;
public final String ginternalname;
private final int gcaptionId;
private final int gdisplaycaptionId;
private static EnumRingLevel[] gRingLevelsSortedOnIndex = null;
private static String[] gCaptionsSortedOnIndex = null;
static
{
gRingLevelsSortedOnIndex = new EnumRingLevel[6];
gRingLevelsSortedOnIndex[0] = DEFAULT;
gRingLevelsSortedOnIndex[1] = SILENT;
gRingLevelsSortedOnIndex[2] = QUIET_BEEP;
gRingLevelsSortedOnIndex[3] = NORMAL_BEEP;
gRingLevelsSortedOnIndex[4] = LOUD_BEEP;
gRingLevelsSortedOnIndex[5] = CUSTOM;
gCaptionsSortedOnIndex = new String[6];
for(int i=0;i<gRingLevelsSortedOnIndex.length;i++)
{
gCaptionsSortedOnIndex[i] = gRingLevelsSortedOnIndex[i].getCaption();
}
}
private EnumRingLevel(
int dbval, int index, String internalname
, int captionResource, int displaycaptionResource)
{
//private constructor
gdbval = dbval;
gindex = index;
ginternalname = internalname;
gcaptionId = captionResource;
gdisplaycaptionId = displaycaptionResource;
}
}
最佳答案
试试这个,
private static var gRingLevelsSortedOnIndex: [EnumRingLevel] = {
return [DEFAULT, SILENT, QUIET_BEEP, NORMAL_BEEP, LOUD_BEEP, CUSTOM]
}()
关于swift - Java 中的静态 block 在 swift 中的等价物是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34065585/
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
用作 mergetool for Git 时,vimdiff 中与 kdiff3 的“从 A/B/C 中选择行”等效的是什么? kdiff3 中是否有类似 Ctrl+1/2/3 的快捷方式? 最佳答案
什么是 Javascript 等同于 imgsrc = $("#content div form img").attr('src'); HTML 是
您好,我有一个数据库可以从中选择 IP 位置> 脚本是在 php 中,我正在将它转换为 java,但我不知道什么是 ip2long('127.0.0.1' )); 在 java 中的等价物 最佳答案
我有一个 C# 应用程序,我正试图将其转换为 Java。 C# 应用程序有几个类型为 ushort 的变量。 Java 中是否有等效项? 谢谢 最佳答案 在大小方面最接近的等价物是 char,因为 J
我正在 iOS 中寻找与 .NET 中的脉冲和等待模式相同的多线程模式。本质上,我希望后台线程处于休眠状态,直到设置标志为止,这实际上是将线程“踢”到行动中。 它是 loop+thread.sle
对于某些并发编程,我可以使用 Java 的 CountDownLatch概念。是否有 C++11 的等效项,或者该概念在 C++ 中称为什么? 我想要的是在计数达到零时调用一个函数。 如果还没有,我会
我正在用 Ruby 开发一个 CLI 应用程序,我想允许通过 /etc/appnamerc 的标准配置文件级联在 Unix 中进行配置。 , ~/.appnamerc .但是,该应用程序也意味着在 W
是否有与 JAXB 等效的 PHP?它被证明对 Java 开发非常有用,作为一个 PHP 新手,我想在 PHP 世界中使用 JAXB 提供的相同概念。 最佳答案 我之前也想找同样的东西,但是找不到。所
Python 有一个 urljoin 函数,它接受两个 URL 并智能地连接它们。有没有在c++中提供类似功能的库? urljoin 文档:http://docs.python.org/library
我有一个从另一种语言移植的功能,你能帮我把它变成“pythonic”吗? 这里的函数以“非pythonic”方式移植(这是一个有点人为的例子 - 每个任务都与一个项目相关联或“无”,我们需要一个不同项
我有 2 个相同类型的对象,我想将一种状态浅复制到另一种状态。在 C++ 中,我有很棒的 memcpy。我怎样才能在 C# 中做到这一点? MemberwiseClone() 不够好,因为它创建并返回
有什么方法可以在 CSS 中使用条件语句吗? 最佳答案 我想说 CSS 中最接近“IF”的是媒体查询,例如可用于响应式设计的媒体查询。对于媒体查询,您是在说“如果屏幕宽度在 440 像素到 660 像
我正在尝试在 Swift 的 iTunesU 中从“为 iphone 和 ipad 开发 ios7 应用程序”中复制 Stanford Matchismo 游戏。 第三讲77页slides ,它显示使
这个问题在这里已经有了答案: Store output of subprocess.Popen call in a string [duplicate] (15 个回答) 关闭4年前。 我想从 pyt
这个问题在这里已经有了答案: Is there a 'foreach' function in Python 3? (14 个回答) 关闭1年前。 我正在深入研究 Python,但我有一个关于 for
我想从 Java 中的这个 Kotlin 类访问信息。它是通过 Gradle 库导入的。 密封类: public sealed class Resource private constructor()
SWT 中的 JPanel 有什么等价物? 最佳答案 原始问题要求 SWT 等同于 JLabel。 还有一个 org.eclipse.swt.custom.CLabel . SWT 等价于 JPane
在诸如 postgres 之类的 SQL 数据库中,我们可以创建 SCHEMA,以便我们可以将我们的表作为 schema_name.table_name 引用。 mongodb 中有模式吗?谢谢 最佳
哪个模型是“GBTRegressor”Pyspark 模型的 Python 等效模型? 简要背景:我正在尝试将 pyspark 模型重新创建为 python 模型。现有管道中使用的模型是 GBTReg
我是一名优秀的程序员,十分优秀!