Swift – 如何知道循环何时结束?

请原谅我,因为我很快就熟悉了,而且一般编程。 相信我,当我说我努力了解这一点,但我根本不能,也不会很感激任何帮助。 说我有这个function: func loop() { for var i=0; i<5; i++ { println(i) } } 我想打印到日志“循环已经完成”,一旦这个循环已经完成并完成运行,我将如何做到这一点? 如果我做: func loop() { for var i=0; i<5; i++ { println(i) println("loop has finished") } } 那么每当我递增时,“循环已经完成”被打印。 我试过阅读closures和完成处理程序,但这一切都在我的头上,而我真的不明白我会如何实现上述任务。 如果有一位天使能够告诉我如何完成我的上面的例子,我会在你的债务。 谢谢你对我目前可怜的知识的耐心!

.xcconfig? 如何设置环境variables

我是Xcode的新手。 我花了最后两天试图找出如何testing我的iPhone上访问Web服务的应用程序。 在模拟器上,我可以使用一个硬编码的“localhost”variables,但我不想硬编码所有的configuration设置。 我使用的是Swift + Xcode 6,但我认为这与Xcode 5是一样的。 我看了很多文章,我想我应该使用.xcconfig,但它是非常不清楚的。 例如,我创build了一个Environment.xcconfig文件。 我用它填充它 API_BASE_URL = "http://localhost:4000/api/v1" 然后我进入了Project – > Info并将Debugconfiguration文件设置为Environment 。 然后我尝试通过${API_BASE_URL}访问代码中的variables,但是我Use of unresolved identifier 'API_BASE_URL' 。 这是非常令人沮丧的。 有任何想法吗?

使用ARC(强/弱)避免循环保留,学习一些基本知识

我似乎还没有遇到问题,但我正在努力确保我正在使用一些最佳做法。 说我有一个UITableViewController与一个NSArray的MyObject对象的数据源。 所以在我的UITableViewController我声明我的数据源如: @property (strong, nonatomic) NSArray *dataSource; 然后,当我触摸一个单元格时,我想推入一个显示某个细节视图的新视图,使用该单元格的MyObject。 所以在新的UIViewController我有这个: @property (strong, nonatomic) MyObject *myObject; 现在在触摸一个单元格的UITableViewController中: MyObject *myObject = [[self dataSource] objectForIndex:[indexPath row]]; NewView *view = [[NewView alloc] initWithMyObject:myObject]; // … push onto nav controller, etc 基本上我害怕的是我的数组被声明为强壮的 ,详细视图中的MyObject声明为强 ,谁知道也许有另一个视图与强壮声明相同的MyObject声明。 底线:这是在视图之间传递对象的正确方法吗? 我的应用程序还没有真正使用过弱引用,我觉得这是不对的。 任何帮助或链接来帮助将是惊人的。

dispatch_sync(dispatch_get_global_queue(xxx),任务)同步或asynchronous

正如苹果的文档所说,dispatch_get_global_queue()是一个并发队列,dispatch_sync是串行的意思。那么这些任务是asynchronous还是同步?

如何在iOS中更改cordova-camera-plugin语言?

我想更改cordova-camera-plugin语言。 显然它依赖于各种各样的东西。 我的开发环境是Visual Studio 2015中的Cordova工具。它不太可能重要,但是我在我的应用程序中使用了Ionic框架。 我们在运行Xcode 7的MacBook Pro笔记本电脑上构buildiOS应用程序。我正在testing的设备是运行iOS 9.1的Ipad,其中荷兰语为第一语言,英语为第二语言。 在我的应用程序,当你打开相机,你有几个选项,如Cancel , Use Photo和Retake Photo 。 我所做的尝试使插件本地化为荷兰语的事情如下。 在config.xml我已经改变了以下行 <widget xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:vs="http://schemas.microsoft.com/appx/2014/htmlapps" id="hop.test1" version="1.0.1" xmlns="http://www.w3.org/ns/widgets" defaultlocale="nl-NL"> 并在我的/platforms/ios/projectname/projectname-Info.plist I have added the以下几行: <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>nl</string> <key>CFBundleLocalizations</key> <array> <string>nl</string> </array> <!– other values omitted !–> </dict> </plist> nl似乎是基于我的search结果周围谷歌和计算器的荷兰正确的本地化符号。 问题是,当我build立我的应用程序,并testing相机,相机button仍然是用英语写的。 我是否实施了错误的东西,我是否在某处丢失了某些值或者是否在本地化了一个Cordova插件的方法是错误的?

用CoreData执行乘法(聚合):如何?

在Jeff Lamarche的一个奇妙的教程之后,我试图为NSManagedObject的特定子类聚合数据。 这是情况。 我创build了一个名为Product的类来扩展NSManagedObject类。 Product类有三个属性,如下所示: @property (nonatomic, retain) NSString* name; @property (nonatomic, retain) NSNumber* quantity; @property (nonatomic, retain) NSNumber* price; 我也创build了一个名为Product+Aggregate的类别,在这里我执行一个总和聚合。 特别是在Jeff教程之后,我pipe理了数量属性的总和。 +(NSNumber *)aggregateOperation:(NSString *)function onAttribute:(NSString *)attributeName withPredicate:(NSPredicate *)predicate inManagedObjectContext:(NSManagedObjectContext *)context { NSString* className = NSStringFromClass([self class]); NSExpression *ex = [NSExpression expressionForFunction:function arguments:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:attributeName]]]; NSExpressionDescription *ed = [[NSExpressionDescription alloc] init]; [ed setName:@"result"]; [ed setExpression:ex]; […]

ARC语义问题“多个方法命名为”setRotation“”而仅存档

我在cocos2dv3中的项目抛出了ARC Sematic发行在归档(发布模式)时发现了多个名为“setRotation:”的方法,结果不匹配,参数types或属性不匹配。 在部署到模拟器/设备(debugging模式)时运行良好。 在发布模式下,编译器会在UIRotationGestureRecognizer和CCNode的旋转实现之间混淆。 当我在CCBAnimationManager.m得到错误时,我调用了将select器setRotation调用为( CCNode *)的对象,但是随后在CCActionInterval出现错误。 我希望有比cocos2d库中的任何地方都更好的解决scheme。 我究竟做错了什么? 感谢您的时间。 编辑 @interface CCAction : NSObject <NSCopying> { id __unsafe_unretained _originalTarget; id __unsafe_unretained _target; NSInteger _tag; } @property (nonatomic,readonly,unsafe_unretained) id target; @property (nonatomic,readonly,unsafe_unretained) id originalTarget; @property (nonatomic,readwrite,assign) NSInteger tag; 在 CCAction.m @synthesize tag = _tag, target = _target, originalTarget = _originalTarget; -(void) startWithTarget:(id)aTarget { _originalTarget = […]

在iOS 7.0.3中不能使用<form target =“_ blank”>

以下代码在iOS 6.0.1中完美运行(使用iOS虚拟键盘,我在input框上按下“Go”button) <html> <body> <form action="http://stackoverflow.com/" target="_blank"> <input type="text" /> </form> </body> </html> 但是当我在iOS 7.0.3上尝试完全相同的代码时,这根本不起作用。 按下iOS键盘上的“Go”button后没有任何反应。 如果我从表单标签中删除[target =“_ blank”],那么它工作正常。 我不知道这个问题的原因是什么。 有没有人有同样的问题?

如何支持所有手机浏览器的PDF查看?

我在用 <object> 在我的网站上embedded一个PDF文件。 例如 <object data="abc.pdf" type="application/pdf"> <embed src="abc.pdf" type="application/pdf" /> </object> 它适用于所有桌面浏览器,但在我的Android设备上,它不显示任何东西。 除了使用谷歌pdf查看器(因为它显着降低pdf质量),有什么办法来支持所有的iOS / Android设备浏览器? 或者,处理这种情况的最好方法是什么? 既然有很多的浏览器,我怎样才能把它们redirect到浏览器的pdf插件下载页面呢,还是我应该告诉他们呢? (用户不太友好)。 谢谢

即使是风景,iPad模式视图控制器仍然以纵向行事

我在横向模式下呈现ModalViewController有一些困难。 基本上,它显示在适当的界面方向,只有当设备被持有在横向模式,但视图控制器的行为,就像是在肖像模式旋转。 我正在呈现这样的模式 – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController]; self.window.rootViewController = navController; [self.window makeKeyAndVisible]; LoginViewController *lvc = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:[NSBundle mainBundle]]; [self.window.rootViewController presentModalViewController:lvc animated:NO]; return YES; } […]