有没有办法在Swift 3中为枚举的关联值添加描述?我希望它们出现在符号文档弹出窗口(选项+单击)中,就像它们对Xcode 8中的函数参数一样.
这是我的枚举:
enum Result {
/**
Request succeeded.
- Parameters:
- something: Some description.
- otherThing: Other description.
*/
case Success(something: Int, otherThing: Int)
/**
Request failed.
- Parameter error: Error.
*/
case Error(error: Error)
}
Run Code Online (Sandbox Code Playgroud)
我尝试过使用- Parameters:,但它在枚举中不起作用.
我在UITableView中有一些UITextFields.用户应该只能插入数字和点.为此,我将键盘类型设置为UIKeyboardTypeNumberPad,并在左下角添加了一个"."按钮.每次按下按钮,都会调用一个函数.此函数应在当前光标位置插入一个点,但这是问题:UITextField没有selectedRange属性,因此我无法获取当前光标位置.有人知道如何解决这个问题,还是有其他方法可以做到这一点?谢谢.
我正在尝试使用映射模型迁移Core Data存储,但是我收到此错误:"持久存储迁移失败,缺少映射模型."
我的应用找到映射模型,但不使用它,即使哈希匹配.这是迁移调试日志:
2013-04-18 23:23:53.256 MyApp[30934:303] CoreData: annotation: Incompatible version schema for persistent store 'file://localhost/Users/Clemens/Library/Containers/com.my-company.MyApp/Data/Library/Application%20Support/com.my-company.MyApp/MyApp.storedata'. store metadata = {
NSPersistenceFrameworkVersion = 407;
NSStoreModelVersionHashes = {
Project = <71e5190c 4e7bdecf 0fcc5df6 72120586 e6ec3b83 9aecd871 6847c9c1 4e888a06>;
Task = <e7df7dad d3710c84 2cc82543 7ef549e2 a4fa5818 b243b97e 5a734d49 5c1ce19f>;
WorkPeriod = <ed62858b 98bacd8d 70442733 07caae00 f82073d8 dd67fd68 c703778f 4b6c7c37>;
};
NSStoreModelVersionHashesVersion = 3;
NSStoreModelVersionIdentifiers = (
""
);
NSStoreType = XML;
NSStoreUUID = "397108D9-D465-41E4-B5FA-45701DAC5B4D";
} and current model versions = {
Project = <919c7227 …Run Code Online (Sandbox Code Playgroud) 有没有办法反转case .A = enumValue并使其类似enumValue != .A?
enum MyEnum {
case A
case B
case C
case D(something: OtherEnum)
}
let enumValue: MyEnum = ...
let otherValue: String = ...
if case .A = enumValue {
// Do nothing
} else {
if otherValue == "something" {
// Do stuff...
} else {
// Do other stuff...
}
}
// More code...
Run Code Online (Sandbox Code Playgroud)
我正在尝试删除空的 if 块并减少行数,所以我不是在寻找类似的东西
var condition1 = true
if case .A = enumValue {
condition1 = …Run Code Online (Sandbox Code Playgroud)