标签: automatic-ref-counting

EXC_BAD_ACCESS 当我关闭窗口时,这也是我的应用程序的委托

EXC_BAD_ACCESS我编写了一个 Cocoa 应用程序,当我关闭应用程序窗口时出现错误。我读到这个错误通常意味着内存问题,但我已经ARC mode打开并且不需要关心释放等(xCode 禁止我调用这个函数并自动管理内存)。

错误指向return NSApplicationMain(argc, (const char **)argv);主函数中的行。

这是我的应用程序的代码:

.h 文件:

@interface MainDreamer : NSWindow <NSWindowDelegate> 
{    
    NSTextField *dreamField;
    NSTableView *dreamTable;    
    NSImageView *dreamview;

    NSMutableArray *dreamlist;  
    NSMutableArray *dataset;
}

@property (nonatomic, retain) IBOutlet NSTextField *dreamField;
@property (nonatomic, retain) IBOutlet NSTableView *dreamTable;
@property (nonatomic, retain) IBOutlet NSImageView *dreamview;
@property (nonatomic, retain) IBOutlet NSMutableArray *dreamlist;
@property (nonatomic, retain) IBOutlet NSMutableArray *dataset;
@property (assign) IBOutlet NSWindow *window;

@end
Run Code Online (Sandbox Code Playgroud)

.m 文件:

@implementation MainDreamer

@synthesize window;
@synthesize dataset;
@synthesize …
Run Code Online (Sandbox Code Playgroud)

macos cocoa exc-bad-access xcode4 automatic-ref-counting

0
推荐指数
1
解决办法
3373
查看次数

为什么 onChange(of:perform:) 的参数被捕获?

我正在使用onChange(of:perform:)SwiftUI 修饰符。然后我想获得旧值,将其与新值进行比较。我阅读了文档,其中说:

闭包可以捕获先前的值以将其与新值进行比较。

举个例子:

.onChange(of: playState) { [playState] newState in
    model.playStateDidChange(from: playState, to: newState)
}
Run Code Online (Sandbox Code Playgroud)

我的问题是为什么在示例中被playState捕获在[ ]? 该playState值无需传入即可轻松访问。此外,这不是类的一部分,因此我认为无法通过捕获self某种类型来创建强引用。

为什么这个例子是这样写的?

automatic-ref-counting swift swiftui

0
推荐指数
1
解决办法
554
查看次数

自动引用计数是否可用作垃圾收集器?

在iOS的最新版本中,Apple已经为Objective-C实现了自动引用计数,但我不明白它的作用.

objective-c automatic-ref-counting

-1
推荐指数
1
解决办法
3229
查看次数

ziparchive Objective-C arc兼容

可能重复:
在iOS中导入zlib时出错:找不到符号collect2:ld

我正在开发iphone项目,我需要一个库来提取ZIP文件,我发现ZipArchive但它与ARC不兼容,当我添加-fno-objc-arc来编译文件时,我得到链接器错误:

体系结构i386的未定义符号:"_inflateEnd",引用自:unzip.o" inflateInit2 " 中的_unzCloseCurrentFile,引用自:unzip.o" _get_crc_table " 中的_unzOpenCurrentFile3 ,引用自:_unzOpenCurrentFile3 in zip.o"_crc32"中的unzip.o _zipOpenNewFileInZip3 ,引用自:_unzReadCurrentFile in zip.o中的unzip.o _zipWriteInFileInZip - ZipArchive.o中的[ZipArchive addFileToZip:newname:]"_inflate",引自:unzip.o中的_unzReadCurrentFile" deflateInit2 ",引自:zip.o中的_zipOpenNewFileInZip3 "_deflate",引用自:zip.o _zipCloseFileInZipRaw in zip.o"_deflateEnd"中的_zipWriteInFileInZip,引自:zip.o中的_zipCloseFileInZipRaw:ld:未找到架构i386 clang的符号:错误:链接器命令失败并带有退出代码1(使用-v查看调用)

objective-c ziparchive ios5 automatic-ref-counting

-1
推荐指数
1
解决办法
5210
查看次数

iOS中的可达性类ARC错误

你好.我导入了reachability.h文件和reachability.m文件,以检查我的应用程序中的Internet连接,但是我收到了ARC错误.

我必须尝试将应用程序转换为ARC,但它仍然显示相同的错误如下:

compile Reachability.m and compile Reachability m files

implicit conversion of objective c pointer type 'Reachability *' to Cpointer type void * requires a bridged  cast

   ARC forbids explicit message send of 'dealloc'
   ARC forbids explicit message send of 'autorelease'
   ARC forbids explicit message send of 'autorelease'

  'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode
  'NSAutoreleasePool' is unavailable: not available in automatic reference counting mode
   Cast of C pointer type 'void*' to Objective - C pointer type …
Run Code Online (Sandbox Code Playgroud)

objective-c reachability ios automatic-ref-counting

-1
推荐指数
1
解决办法
1571
查看次数

__bridge 在 Objective C 中意味着什么?

我正在关注 Core Graphics 中的教程,并且遇到了代码 __bridge。我查看了一下,发现它与 ARC 有关,但我对它的作用感到困惑。有人可以解释它在这种情况下的作用吗?

    void drawLinearGradient(CGContextRef context, CGRect rect, CGColorRef startColor, CGColorRef endColor)
{
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGFloat locations[] = { 0.0, 1.0 };

    NSArray *colors = @[(__bridge id) startColor, (__bridge id) endColor];

    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations);

}
Run Code Online (Sandbox Code Playgroud)

core-graphics objective-c automatic-ref-counting

-2
推荐指数
1
解决办法
3967
查看次数

insertObject:atIndex:overObjectObjectItIndex:withObject:on NSMutableArray的好处是什么

当使用NSMutableArray中的新值替换某个索引处的值时,旧值将保留在内存中.修复的方法是在每个循环之前初始化一个新的NSMutableArray.

重现步骤:

- (id) init{
    self.overlays = [[NSMutableArray alloc] initWithCapacity: [self.anotherArray count]];
}

- (void) someOtherMethod{
    for(int i = 0 ; i < self.anotherArray ; i++){
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
        [view setBackgroundColor:[UIColor colorWithRed:0 
                                                green:0 
                                                 blue:0 
                                                alpha:1]];
        [view setAlpha: .2];
        [self.overlays insertObject:view atIndex: i]
    }
}

- (void) main{
    for(int i = 0 ; i < 4 ; i++){
        [myObject someOtherMethod];
    }
}
Run Code Online (Sandbox Code Playgroud)

insertObject:atIndex有效地导致内存泄漏,因为它不会释放该索引处的数组中的旧值.

我提交了一份错误报告,Apple回答说:

insertObject:atIndex:表现为已定义.它正在插入,而不是替代.如果要替换,则应使用-replaceObjectAtIndex:withObject:

insertObject:atIndex:怎么可能有任何好处,因为你总是丢失对该索引的旧对象的引用.

这是否只是为了避免修复问题,因为它符合旧的文档定义?

cocoa objective-c nsmutablearray automatic-ref-counting

-3
推荐指数
1
解决办法
1323
查看次数

ARC禁止显式消息发送'保留'

当我遇到问题时,我正在构建ios应用程序.它说ARC禁止显式消息发送'保留'.这是我的代码,给我错误.

    filePath= [[NSString stringWithFormat:@"%@", [[NSBundle mainBundle] resourcePath]] retain];
Run Code Online (Sandbox Code Playgroud)

我该怎么办?我的ARC已开启,我希望它继续使用,以便我能做什么.

ios automatic-ref-counting

-4
推荐指数
1
解决办法
241
查看次数

ARC 不允许将“int”隐式转换为“id _Nonnull”

这段代码:

[selectedTagIndexes addObject: (int)sender.tag - 100];
Run Code Online (Sandbox Code Playgroud)

产生一个错误:

ARC 不允许将“int”隐式转换为“id _Nonnull”

compiler-errors objective-c automatic-ref-counting

-4
推荐指数
1
解决办法
6372
查看次数