我已经成功创建了一个响应这些操作的Xcode 8模板:
一步一步,如何实现:
我创建于:
/Users/*YOUR_USER_NAME*/Library/Developer/Xcode/Templates/File Templates
Run Code Online (Sandbox Code Playgroud)
文件夹名称 Custom/Interactor.xctemplate
该文件夹中的文件:
因此,当我右键单击并创建新文件时,我将选择自定义文件:
上面的示例工作并创建我的自定义文件:
我想要实现的目标:
我正在尝试创建一个包含新自定义文件的组.不需要实际的文件夹或复杂的任务,只需要包含实际文件的组.
所以最终结果将是:
由于没有解释如何创建自定义模板的文档,我使用了很多引用:ref1,ref2,ref3,ref4.
这是TemplateInfo.plist文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DefaultCompletionName</key>
<string>MyCustomInteractor</string>
<key>Description</key>
<string>Custom interactor</string>
<key>Kind</key>
<string>Xcode.IDEKit.TextSubstitutionFileTemplateKind</string>
<key>Options</key>
<array>
<dict>
<key>Description</key>
<string>Custom interactor</string>
<key>Identifier</key>
<string>fileName</string>
<key>Name</key>
<string>Custom name</string>
<key>NotPersisted</key>
<true/>
<key>Required</key>
<true/>
<key>Type</key>
<string>text</string>
</dict>
<dict>
<key>Default</key>
<string>___VARIABLE_fileName:identifier___</string>
<key>Identifier</key>
<string>productName</string>
<key>Type</key>
<string>static</string>
</dict>
<dict>
<key>Default</key> …Run Code Online (Sandbox Code Playgroud) 将Integer数组转换为int数组的最佳方法是什么?
它的简单解决方案是:
public int[] toPrimitiveInts(Integer[] ints) {
int[] primitiveInts = new int[ints.length];
for(int i = 0; i < ints.length; i++) {
primitiveInts[i] = ints[i] == null ? 0 : ints[i];
}
return primitiveInts;
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,我采用0了null对象/包装器的默认值为null并且int为0这一事实的值.
但我找不到将Integer []转换为int []的简单方法.