我正在完成我的核心数据应用程序和我开始我的最终测试.
Everyfing工作正常,除了一件事,随机发生,我无法重现它.
这是日志(使用NSZombieEnabled):
2011-07-03 20:27:53.144 MYAPP[1882:707] -[__NSCFType controllerWillChangeContent:]: unrecognized selector sent to instance 0x4a4c490
2011-07-03 20:27:53.149 MYAPP[1882:707] Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. -[__NSCFType controllerWillChangeContent:]: unrecognized selector sent to instance 0x4a4c490 with userInfo (null)
2011-07-03 20:27:53.165 MYAPP[1882:707] CoreAnimation: ignoring exception: -[__NSCFType controllerWillChangeContent:]: unrecognized selector sent to instance 0x4a4c490
Run Code Online (Sandbox Code Playgroud)
它在这里崩溃:
NSManagedObjectContext *context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; // IT'S OK
NSManagedObject *newManagedObject = …
Run Code Online (Sandbox Code Playgroud) iphone core-data nsfetchedresultscontroller nsmanagedobjectcontext
这里有人可以看看代码并告诉我它有什么问题吗?我基本上是试图构建一对夫妇的是对某些原始类型,如操作的通用功能Int
,Float
,Double
等.
不幸的是我无法让它正常工作.这是(部分)工作的代码:
// http://stackoverflow.com/a/24047239/2282430
protocol SummableMultipliable: Equatable {
func +(lhs: Self, rhs: Self) -> Self
func *(lhs: Self, rhs: Self) -> Self
}
extension Double: SummableMultipliable {}
func vec_dot<T where T: SummableMultipliable>(a : [T], b: [T]) -> Double {
assert(a.count == b.count, "vectors must be of same length")
var s : Double = 0.0
for var i = 0; i < a.count; ++i {
let x = (a[i] * b[i]) as Double
s = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用UIAlertController
iOS 8中引入的新功能.除了UIAlertAction
总是最终在其回调中解除警报控制器这一事实外,一切都很有效.以下是我的代码:
let alert = UIAlertController(title: "New Group", message: "Enter Group name", preferredStyle: UIAlertControllerStyle.Alert);
alert.addTextFieldWithConfigurationHandler({ [weak self] (nameField: UITextField!) in
nameField.becomeFirstResponder();
nameField.delegate = self;
return;
})
alert.addAction(UIAlertAction(title: "Done", style: .Default, handler: { action in
println("Done Entering");
}));
alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil));
self.presentViewController(alert, animated: true, completion: nil);
Run Code Online (Sandbox Code Playgroud)
现在,当我单击"完成"按钮时,控件进入回调方法,然后警报被解除,即使我没有任何声明来解除警报.这种行为是默认的吗?如果是,我怎样才能确保在某些情况下警报停留在屏幕上(取决于我的条件)?我在这里错过了什么吗?
我真的很感激有关这方面的任何帮助.
我有这个扩展名:
extension UIColor {
func rgba(r: Int, g: Int, b: Int, a: Float) -> UIColor {
return UIColor(red: r/255, green: g/255, blue: b/255, alpha: a)
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我一条错误信息: Extra argument 'green' in call
我不知道为什么会发生这种情况,可能是xcode 6 beta 4或swift中的错误.
我尝试在swift中为我的MKPointAnnotation创建一个自定义的"badget",但它失败了,因为MKPointAnnotation没有像图像那样的任何属性
var information = MKPointAnnotation()
information.coordinate = location
information.title = "Test Title!"
information.subtitle = "Subtitle"
information.image = UIImage(named: "dot.png") //this is the line whats wrong
Map.addAnnotation(information)
Run Code Online (Sandbox Code Playgroud)
有人想出了一个快速的解决方案吗?
我尝试在Swift中打开文件.为此,我创建了文件路径.它不起作用.
maaaacy:~ $ pwd
/Users/tsypa
maaaacy:~ $ cat a.txt
test
maaaacy:~ $ ./a.swift
nil!
maaaacy:~ $
Run Code Online (Sandbox Code Playgroud)
剧本:
#!/usr/bin/xcrun swift
import Foundation
var filePath = NSBundle.mainBundle().pathForResource("a", ofType: "txt", inDirectory: "/Users/tsypa")
if let file = filePath {
println("file path \(file)")
// reading content of the file will be here
} else {
println("nil!")
}
Run Code Online (Sandbox Code Playgroud)
怎么了?
我想在我的自定义类中实现下标,从而实现以下方法:
- (id)objectForKeyedSubscript:(id <NSCopying>)key NS_AVAILABLE(10_8, 6_0);
- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key NS_AVAILABLE(10_8, 6_0);
Run Code Online (Sandbox Code Playgroud)
但我有一个奇怪的问题,因为我以前从未见过它:[(id)obj isKindOfClass:]
抛出一个ARC语义问题:
没有已知的选择器实例方法'isKindOfClass:'
据我所知,之前我没有遇到任何问题id
......这是Xcode的错误(是的,我使用的是Xcode 5 DP2),还是我忘记了重要的事情?
- (id)objectForKeyedSubscript:(id <NSCopying>)key {
if(![key isKindOfClass:[NSString class]]) { // ERROR
...
} else {
...
}
}
Run Code Online (Sandbox Code Playgroud)
注意:我不想听到"哦,这是在NDA之下,不应该在这里讨论".我不讨论任何API,功能,等等.我只是让你知道我正在使用测试版软件,所以它可能只是一个简单的bug.
所以我想要一个警告弹出告诉我一条消息,然后我希望它等我,直到我按OK然后它将继续该功能.例如.
@IBAction Alert() {
let alertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
问题是,现在它不会做任何事情,如果我之后只是放入一个函数它直接执行,而不是等到我按下OK.有谁知道如何做到这一点?
顺便说一下,在这个例子中,消息将是标题,消息,我知道,这不是我在这种情况下需要的;)
提前致谢!
我正在尝试编写一个C代码,它将在屏幕上打印金字塔结构,就像这样.
我写的相应代码是这样的.
#include <stdio.h>
#include <stdlib.h>
void printArrayFunc(char arr[9][5])
{
int i,j;
printf("=========================================\nprinting the values\n");
for (i = 0; i<5; i++)
{
for (j = 0; j<9;j++)
{
//printf("arr[%d][%d] = %d\n", i,j, arr[i][j]);
if (arr[i][j] == 1)
printf("*");
else
printf(" ");
}
printf("\n");
}
}
int main()
{
int i,j;
char arr[9][5] = {0};
printf("============================\nfilling the values\n") ;
for (i=0;i<5;i++)
{
for (j= 4-i;j<=4+i;j++)
{
arr[i][j] = 1;
// printf("arr[%d][%d]= %d\n",i,j,arr[i][j]);
}
//printf("\n");
}
printArrayFunc(arr);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它给出了类似的输出
我知道我犯了一些愚蠢的错误,但此时此刻,我无法找到出错的地方.让我听听你对此的评论.