我正在检查一些崩溃,所有崩溃都有SIGSEGV信号,原因是SEGV_ACCERR.在搜索SEGV_ACCERR之后,我发现最接近人类可读解释的是:对象的无效权限
这在更一般意义上意味着什么?何时出现SEGV_ACCERR?关于这个原因有更具体的文件吗?
我试图找出为什么maven项目没有包装罐子.这是我的同事计算机上的成功构建.我构建时没有错误,但jar不在目标文件夹中.我希望通过从maven进程获得更详细的输出,我可以确定我的安装和其他人员安装之间的差异.
我有两个集合:
let collection1:[String:[String:NSObject]] = ["somekey":["nestedkey":"value"]]
let collection2:[String:[String:NSObject]] = ["somekey":["nestedkey":"value"]]
//I would like to compare them using the following:
let collectionsAreEqual = collection1 == collection2
Run Code Online (Sandbox Code Playgroud)
将上述代码复制并粘贴到操场中会出现以下错误:

我知道我可以为此写一个相同的功能:
infix func == (this:[String:[String:NSObject]], that:[String:[String:NSObject]]){
//return true or false
}
Run Code Online (Sandbox Code Playgroud)
在目标c中,isEqual:在NSDictionary上处理这个没问题,因为它为你做了嵌套比较.是否有一些通常在swift中处理这个的方法?
更新
我可以使用以下内容:
//:[String:[String:NSObject]]
let collection1:[String:NSObject] = ["somekey":["nestedkey":"value"]]
let collection2:[String:NSObject] = ["somekey":["nestedkey":"value"]]
//I would like to compare them using the following:
let collectionsAreEqual = collection1 == collection2
Run Code Online (Sandbox Code Playgroud)
但它需要使用NSObject作为声明中的值.有没有一个纯粹的快速方法来处理这个?
我有一种偶尔崩溃的方法.
-(void)foo{
[self doSomething];
[self.delegate didFinish];
[self doSomethingElse];
}
Run Code Online (Sandbox Code Playgroud)
-doSomething工作正常,然后我打电话给委托-didFinish.在-didFinish中,对此对象的引用可能设置为nil,在ARC下释放它.当方法崩溃时,它会在-doSomethingElse上执行此操作.我的假设是自我在一个方法中会很强大,允许函数完成.自我弱还是强?有关于此的文件吗?它的强弱是什么原因?
编辑
在受到以下一些答案的启发后,我做了一些调查.在我的情况下崩溃的实际原因是NSNotificationCenter在任何情况下都不保留观察者.Mike Weller在下面指出方法的调用者应该在调用它时保留对象以防止我上面描述的情况,但是看起来NSNotificationCenter忽略了这个问题,并且始终保持对观察者的弱引用.换一种说法:
-(void)setupNotification{
//observer is weakly referenced when added to NSNotificationCenter
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleNotification:)
name:SomeNotification object:nil];
}
//handle the notification
-(void)handleNotification:(id)notification{
//owner has reference so this is fine
[self doSomething];
//call back to the owner/delegate, owner sets reference to nil
[self.delegate didFinish];
//object has been dealloc'ed, crash
[self doSomethingElse];
}
Run Code Online (Sandbox Code Playgroud) messaging reference-counting objective-c self automatic-ref-counting
我有一个应用程序,我称之为内存吃,这是为了迫使其他应用程序被操作系统转储.它通过消耗大量内存来实现这一点,直到它因内存压力而终止.为了消耗内存,我基本上制作了数据的JPEG表示的副本:
-(IBAction)didTapStartButton:(id)sender{
int i = 200;
while (i>0) {
NSData* data = [UIImagePNGRepresentation(self.image) mutableCopy] ;
[self.array addObject:[[data description] mutableCopy]];
[self.array addObject:data];
i--;
}
}
Run Code Online (Sandbox Code Playgroud)
这完全是通过反复试验完成的,我认为有一种更直接的方式来消耗大量的内存.
在objective-c中,我们有一个-forwardInvocation:可以像这样使用:
-(void)forwardInvocation:(NSInvocation*) anInvocation{
BOOL didForward = NO;
//iterate over our proxied objects
for(id proxyObject in self.proxyObjects){
//invoke the with the proxy object if it can handle the selector
if ([proxyObject respondsToSelector:[anInvocation selector]]){
didForward = YES;
[anInvocation invokeWithTarget: proxyObject];
}
}
//if we did not forward the invocation, then call super
if(!didForward){
[super forwardInvocation: anInvocation];
}
}
Run Code Online (Sandbox Code Playgroud)
当你有一组所有需要相同消息的具体类时,这很有用.例如,如果您要实现多个分析平台,每个平台都需要相同的消息,但会以不同的方式处理它们.
鉴于我们对语言的了解,让我们快速做到这一点.这开始很简单:
func doSomething1(){
for proxyObject in proxyObjects{
proxyObject.doSomething1()
}
}
Run Code Online (Sandbox Code Playgroud)
但后来变得重复:
func doSomething2(){
for proxyObject in proxyObjects{
proxyObject.doSomething2()
}
}
func doSomething3(){
for …Run Code Online (Sandbox Code Playgroud)