在Xcode的项目导航器中,我不确定是什么?试图告诉我文件名旁边.

我确信这是从我的项目根目录拖到Classes文件夹的同一个文件并不是巧合(因为.mm文件在那里,我希望它们在一起).该项目仍然编译得很好,但我的代码意识最近破了,我想知道这是否可能是问题的一部分.
谢谢!
我是Swift的新手,正在尝试调度程序.我选择了开始时间,我需要在开始时间加5分钟(或它的倍数)并将其显示在UILabel中?
@IBAction func timePickerClicked(sender: UIDatePicker) {
var dateFormatter = NSDateFormatter()
dateFormatter.timeStyle = NSDateFormatterStyle.ShortStyle
var dateStr = dateFormatter.stringFromDate(startTime.date)
let sttime = dateStr
startTimeDisplay.text = dateStr
}
// How to advance time by 5 minutes for each section based on the start time selected and display time
// section 1 = start time + 5
// section 2 = start time + 10*
Run Code Online (Sandbox Code Playgroud) 我正在编写一个需要高精度和低频率的背景位置更新的应用程序.该解决方案似乎是一个后台NSTimer任务,它启动位置管理器的更新,然后立即关闭.之前已经问过这个问题:
但我还没有得到最起码的例子.在尝试了上述接受的答案的每一个排列后,我总结了一个起点.输入背景:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
self.bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"ending background task");
[[UIApplication sharedApplication] endBackgroundTask:self.bgTask];
self.bgTask = UIBackgroundTaskInvalid;
}];
self.timer = [NSTimer scheduledTimerWithTimeInterval:60
target:self.locationManager
selector:@selector(startUpdatingLocation)
userInfo:nil
repeats:YES];
}
Run Code Online (Sandbox Code Playgroud)
和委托方法:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
NSLog(@"%@", newLocation);
NSLog(@"background time: %f", [UIApplication sharedApplication].backgroundTimeRemaining);
[self.locationManager stopUpdatingLocation];
}
Run Code Online (Sandbox Code Playgroud)
当前行为是backgroundTimeRemaining从180秒减少到零(记录位置时),然后执行到期处理程序,不再生成进一步的位置更新.如何修改上述代码以便在后台无限期地接收定期位置更新?
更新:我的目标是iOS 7,似乎有一些证据表明后台任务的行为有所不同:
objective-c core-location ios background-task ios-background-mode
我们如何在快速忽略的情况下比较两个字符串?例如:
var a = "Cash"
var b = "cash"
Run Code Online (Sandbox Code Playgroud)
如果我们比较var a&var b,是否有任何方法会返回true
我正在尝试在Xcode中生成UItest.当我尝试刷UIview时出现错误:
Timestamped Event Matching Error: Failed to find matching element
Run Code Online (Sandbox Code Playgroud)
如果我尝试点击UIView,也会发生这种情况.
我正在尝试添加一个由cocoapods添加的pod,我正在使用swift 3,而pod(SQlite.swift).
我试图使用没有最新swift版本的高手,但是有一个分支为swift 3.
那么我应该如何设置我的podfile来下载特定的分支?可能吗?
这是我的podfile:
platform :ios, '10.0'
target 'RedShirt' do
use_frameworks!
# Pods for RedShirt
pod 'SQLite.swift', :git => 'https://github.com/stephencelis/SQLite.swift.git'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
Run Code Online (Sandbox Code Playgroud) 我想列出一个中的所有子视图UIViewController.我尝试过self.view.subviews,但并未列出所有子视图,例如,UITableViewCell未找到子视图.任何的想法?
在Swift中,如何在switch语句中编写一个case来测试根据可选内容切换的值,如果可选包含,则跳过case nil?
以下是我的想象:
let someValue = 5
let someOptional: Int? = nil
switch someValue {
case someOptional:
// someOptional is non-nil, and someValue equals the unwrapped contents of someOptional
default:
// either, someOptional is nil, or someOptional is non-nil but someValue does not equal the unwrapped contents of someOptional
}
Run Code Online (Sandbox Code Playgroud)
如果我只是这样编写它,编译器抱怨someOptional没有解开,但如果我通过添加!到结尾显式解包,我当然会在任何时候someOptional包含运行时错误nil.添加?而不是!对我有意义(在可选链接的精神,我想),但不会使编译器错误消失(即实际上不打开可选的).
关于如何通过显示和解除多个视图控制器解决问题,我在最后一周打破了我的头脑.我创建了一个示例项目并直接从项目中粘贴代码.我有3个视图控制器及其相应的.xib文件.MainViewController,VC1和VC2.我在主视图控制器上有两个按钮.
- (IBAction)VC1Pressed:(UIButton *)sender
{
VC1 *vc1 = [[VC1 alloc] initWithNibName:@"VC1" bundle:nil];
[vc1 setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:vc1 animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
这打开VC1没有问题.在VC1中,我有另一个按钮,它应该打开VC2,同时解除VC1.
- (IBAction)buttonPressedFromVC1:(UIButton *)sender
{
VC2 *vc2 = [[VC2 alloc] initWithNibName:@"VC2" bundle:nil];
[vc2 setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:vc2 animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
} // This shows a warning: Attempt to dismiss from view controller <VC1: 0x715e460> while a presentation or dismiss is in progress!
- (IBAction)buttonPressedFromVC2:(UIButton *)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
} // This is going back to VC1.
Run Code Online (Sandbox Code Playgroud)
我希望它回到主视图控制器,同时VC1应该已经从内存中删除了.只有当我点击主控制器上的VC1按钮时才会显示VC1.
主视图控制器上的另一个按钮也应该能够直接绕过VC1显示VC2,并且当在VC2上单击按钮时应该返回到主控制器.没有长时间运行的代码,循环或任何计时器.只是裸骨调用来查看控制器.
objective-c uiviewcontroller ios presentviewcontroller dismissviewcontroller