有一个像这样的代码:
switch (indexPath.section, indexPath.row) {
case (0, 1...5): println("in range")
default: println("not at all")
}
Run Code Online (Sandbox Code Playgroud)
问题是我可以在第二元组值中使用多个区间吗?
对于非元组切换,它可以很容易地完成
switch indexPath.section {
case 0:
switch indexPath.row {
case 1...5, 8...10, 30...33: println("in range")
default: println("not at all")
}
default: println("wrong section \(indexPath.section)")
}
Run Code Online (Sandbox Code Playgroud)
我应该使用哪个分隔符来分隔元组内部的间隔,或者它不适用于元组开关,我必须在开关内使用开关?谢谢!
让我们说,我有UIViewController子类:
class InformationServiceMenuVC <T : InformationServiceItemProtocol>: UITableViewController {
}
Run Code Online (Sandbox Code Playgroud)
通常我可以通过调用以下内容来创建视图控制器的实例:
let vc = InformationServiceSideMenuVC<InformationServiceMenuItem>()
Run Code Online (Sandbox Code Playgroud)
但是在使用故事板时如何传递所需的通用类型?
使用LocalAuthentication时遇到问题并支持iOS 7.0
当我想要的时候
import LocalAuthentication
Run Code Online (Sandbox Code Playgroud)
如果目标iOS版本低于8.0,我就会崩溃.
我尝试在构建阶段将LocalAuthentication.framework标记为可选,并通过调用以下方法检查类可用性:
var isTouchIDSupported: Bool {
if let contextClass: AnyClass = NSClassFromString("LAContext") {
return LAContext().canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: nil)
}
return false
}
Run Code Online (Sandbox Code Playgroud)
如果我评论LAContext()字符串,它不会崩溃:
var isTouchIDSupported: Bool {
if let contextClass: AnyClass = NSClassFromString("LAContext") {
//return LAContext().canEvaluatePolicy(.DeviceOwnerAuthenticationWithBiometrics, error: nil)
}
return false
Run Code Online (Sandbox Code Playgroud)
}
如果我在代码的任何地方访问任何LA类(例如LAContext),它会在应用程序启动的第一秒崩溃.我在这里做错了什么?
此崩溃的控制台日志:
dyld: Symbol not found: _objc_isAuto
Referenced from: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
Expected in: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/usr/lib/libobjc.A.dylib
in /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
Run Code Online (Sandbox Code Playgroud) 我有以下代码来获取和分组搜索结果:
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Song"];
[request setPredicate:[NSCompoundPredicate andPredicateWithSubpredicates:predicates]];
[request setResultType:NSDictionaryResultType];
[request setSortDescriptors: @[[NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:YES]]];
NSExpression *countExpression = [NSExpression expressionWithFormat:@"count:(SELF)"];
NSExpressionDescription *expressionDescriprion = [[NSExpressionDescription alloc] init];
[expressionDescriprion setName:@"count"];
[expressionDescriprion setExpression:countExpression];
[expressionDescriprion setExpressionResultType:NSInteger64AttributeType];
NSArray *properties = @[@"artistName", @"songName"];
[request setPropertiesToFetch:[properties arrayByAddingObject:expressionDescriprion]];
[request setPropertiesToGroupBy:properties];
self.fetchedItems = [self.managedObjectContext executeFetchRequest:request error:nil];
Run Code Online (Sandbox Code Playgroud)
哪个工作非常好但是我遇到了问题并且有点被困,所以我需要以某种方式使这个propertiesToGroupBy(属性类型是NSString*)不区分大小写.目前我有以下输出:
<_PFArray 0x7fa3e3ed0d90>(
{
artistName = "System of a Down";
count = 44;
songName = "Lonely Day";
},
{
artistName = "System Of A Down";
count = …Run Code Online (Sandbox Code Playgroud) 在我安装了本机 Cocoapods 应用程序之后,从那一刻起,我在终端中看到了以下内容:
pod --version
1.0.0.beta.3
Run Code Online (Sandbox Code Playgroud)
现在我需要使用特定版本的 cocoapods,但即使在我从 mac 中完全删除 cocoapods 后,我也有相同的输出 1.0.0.beta.3。我卸载了列出的所有与 cocoapods 相关的东西,gem list但版本从未改变
如果我删除 cocoapods.app,我会得到以下内容:
pod --version
[!] Unable to locate the CocoaPods.app application bundle. Please ensure the application is available and launch it at least once.
Trace/BPT trap: 5
Run Code Online (Sandbox Code Playgroud)
有人能帮我解决这个问题吗?也许我需要更改 Pod 的系统目录,但我不知道从哪里开始查找。
谢谢指教!
有人可以解释找出Int类型的最佳方法,因为Swift 4因为这个原因我有很多麻烦
因为当我尝试将相同的json对象映射到核心数据实体和PONSO时,这是很常见的情况
所以,
id: Int = json["id"] as? Int // works
id: Int32 = json["id"] as? Int32 // doesn't work
Run Code Online (Sandbox Code Playgroud)
结果我无法同时满足这两个要求.我能不能在Swift 4中避免这种绝对无意义的int情况?