当我创建项目时,我检查了"使用自动引用计数".现在,我想把它关掉,但我找不到改变它的地方.
还有一件事,是否建议将ARC用于iPad/iPhone应用程序?
我试图将这段代码合并到一个新的(iOS 5)项目中......问题是,我正在使用ARC,它真的不喜欢编写的代码.
我已经能够解决大多数错误,但我遇到了3个错误,我似乎无法弄清楚.
错误#1:
对于unsafe_unretained属性'delegate'的现有ivar'委托'必须是_unsafe_unretained
.H
@interface SKPSMTPMessage : NSObject {
NSOutputStream *outputStream;
NSInputStream *inputStream;
id <SKPSMTPMessageDelegate> delegate;
}
@property(nonatomic, assign) id <SKPSMTPMessageDelegate> delegate;
Run Code Online (Sandbox Code Playgroud)
.M
@synthesize login, pass, relayHost, relayPorts, subject, fromEmail, toEmail, parts, requiresAuth, inputString, wantsSecure, \
delegate, connectTimer, connectTimeout, watchdogTimer, validateSSLChain;
Run Code Online (Sandbox Code Playgroud)
错误#2:
将非本地对象的地址传递给_autoreleasing参数以进行回写
.H
@interface SKPSMTPMessage : NSObject {
NSOutputStream *outputStream;
NSInputStream *inputStream;
id <SKPSMTPMessageDelegate> delegate;
}
Run Code Online (Sandbox Code Playgroud)
.M
[NSStream getStreamsToHostNamed:relayHost port:relayPort inputStream:&inputStream outputStream:&outputStream];
Run Code Online (Sandbox Code Playgroud)
任何指导将不胜感激.
谢谢.
我有一些内部块的操作.此操作,只更新UIImage如下:
^(UIImage *image) {
self.myImage = image;
}];
Run Code Online (Sandbox Code Playgroud)
我的图像是通过访问互联网计算的NSURLConnection.当我从互联网上收到图像时,我称之为内部的那个块NSMutableArray.到现在为止还挺好.我的问题是,当我有多个具有相同URL的图像,而不是进行多次调用时,我只是NSMutableArray在处理连接的类内部添加一个新块.这样,我进行一次调用,并更新共享URL的多个图像.一切正常,问题是我在泄漏块.我将这样的块添加到NSMutableArray:
if( (self = [super init]) )
{
self.connectionURL=url;
self.arrayOfBlocks=[NSMutableArray array];
[arrayOfBlocks addObject:completion];
}
return self;
Run Code Online (Sandbox Code Playgroud)
这是初始化连接类的时候.这是我需要添加一个新块NSMutableArray(我只添加它,就是这样):
[arrayOfBlocks addObject:completion];
Run Code Online (Sandbox Code Playgroud)
这是当我最终收到回调并开始执行块时:
for (MyBlock blockToExecute in arrayOfBlocks)
{
blockToExecute([UIImage imageWithData:data]);
}
Run Code Online (Sandbox Code Playgroud)
问题是,这是以某种方式泄漏.我无法抵消使用版本或自动发布,因为我在ARC环境中.那么什么可以解决方案呢?

nsurlconnection ios objective-c-blocks automatic-ref-counting
我最近升级到Xcode 4.4并且已经将它用于一些Mac App Store提交.两个工作正常,但第三个给出了这个错误:
Undefined symbols for architecture x86_64:
"_objc_retain", referenced from:
___ARCLite__load in libarclite_macosx.a(arclite.o)
(maybe you meant: _objc_retainedObject)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
ARC已关闭,因此我不知道此引用的来源,或者如何摆脱它.我已经尝试过通常的清洁/构建周期,但无济于事.
有什么想法吗?
我应该在什么情况下使用此功能?
它到底有多成熟?
优缺点都有什么?
它解决了什么问题?
它是否特定于MonoTouch,Mono GC或ObjC中的引用计数?

我在ARC中使用此代码:
NSMutableDictionary *datesDict = [[NSMutableDictionary alloc]init];
NSMutableArray *datesArray = [[NSMutableArray alloc]init];
for (NSString *key in programsArray) {
datesArray = [_onDemandDictionary objectForKey:key];
NSMutableArray *newDates = [[NSMutableArray alloc]init];
int count;
for (count = 0; count <datesArray.count; count++) {
NSMutableDictionary *programsDict = [[NSMutableDictionary alloc]init];
programsDict = [datesArray objectAtIndex:count];
[newDates addObject:[programsDict objectForKey:@"date"]];
}
[datesDict setObject:newDates forKey:key];
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行分析器工具时,我在初始化期间将值存储到(datesArray和programsDict),从不在行上读取:
NSMutableArray *datesArray = [[NSMutableArray alloc]init];
programsDict = [datesArray objectAtIndex:count];
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?如何隐藏警告?
谢谢!
我对Objective-C很新,我有一个问题.
我创建了一个自定义类,并尝试为初始化创建重载:
- (id)init
{
if (self = [super init]) {
[self setIsCurrentCar:NO];
}
return self;
}
-(id) initWithID:(NSInteger)id {
if(self = [self init]) {
[self setID:id];
}
return self;
}
-(id) initWithID:(NSInteger)id CarYear:(NSString *)year {
if(self = [self initWithID:id]) {
[self setCarYear:year];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
让我们说一下,我称之为-(id) initWithIDCarYear方法.
我想知道上面的代码在结构上是正确的.
self设置为3次.有更好的解决方案吗?if(self = ...)始终检查或者它是冗余代码?谢谢
@Edit 以下代码更好吗?
-(id) initWithID:(NSInteger)id CarYear:(NSString *)year {
if (self = [super init]) {
[self setIsCurrentCar:NO];
[self setID:id];
[self …Run Code Online (Sandbox Code Playgroud) 我试图通过创造类别"假"的实例变量objc_setAssociatedObject的描述,在此职位.
但是,我在iOS 6.1中使用ARC会出现以下错误:Use of undeclared identifier 'OBJC_ASSOCIATION_RETAIN对于以下代码段:
- (void)setStyleName:(NSString *)styleName
{
objc_setAssociatedObject(self, kDHStyleKey, styleName,
OBJC_ASSOCIATION_RETAIN);
}
Run Code Online (Sandbox Code Playgroud)
iOS 6.1有什么变化吗?
我错过了什么?
所以我Core Data用来存储一些图像.(也是最新生成的子类mogenerator)
(而且我也在使用ARC)
是的,我知道我可以保留一个参考并将其存储在磁盘上,但我想:
"嘿,他们做了一个选择,所以我可以做到这一点,而不必亲自管理它!"
所以我尝试了它并且它完美地工作,除了所有加载的数据从未发布.


在ViewController的初始化中,谁将负责显示图像,我给它通常的主要NSManagedObjectContext.
在viewDidAppear我调用的方法中,我设置了UIScrollView图像:
编辑:所以这不是一个真正的获取请求,我有Entity1一对多的图像,我用它来获取我从同一个上下文得到这个entity1的图像.我只想简化以便更好地解释.
- (void)setupScrollViewWithEntity1:(Entity1 *)entity1 {
DDLogVerbose(@"-- %@ : SETUP SCROLL VIEW --", self);
// I remove any previous subviews
[self.scrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
self.scrollView.contentSize = self.scrollView.frame.size;
/* Here I get the imagesArray with a NSFetchRequest */
//So it's not really a fetch request I have an `Entity1` which have one-to-many with images and I use it to get the images …Run Code Online (Sandbox Code Playgroud) 有人可以告诉我为什么localComplete块和self.block的内存地址是一样的吗?self.complete的属性设置为copy,并且为了确保我在将localComplete分配给self.complete时也在localComplete上调用copy.
- (void) test {
CompletionBlock localComplete = ^{
};
NSLog(@"localComplete - %p", localComplete);
self.block = [localComplete copy];
NSLog(@"self.complete - %p", self.block);
self.block();
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
2013-10-05 08:39:18.549 TestApp[90703:a0b] localComplete - 0x60b8
2013-10-05 08:39:18.550 TestApp[90703:a0b] self.complete - 0x60b8
Run Code Online (Sandbox Code Playgroud)
另一个例子我创建字符串:
// creating string
self.carType = [[NSString alloc] initWithFormat: @"Good%@", @"year"];
NSLog(@"self.carType - %p", self.carType);
// same memory address???
NSString *carInitString = [[NSString alloc] initWithString: self.carType];
NSLog(@"carInitString - %p", carInitString);
// same memory address???
NSString *carCopy = [self.carType copy];
NSLog(@"carCopy - %p", carCopy); …Run Code Online (Sandbox Code Playgroud) objective-c ×7
ios ×6
cocoa-touch ×2
iphone ×2
core-data ×1
ios5 ×1
ios6 ×1
memory-leaks ×1
xamarin.ios ×1
xcode ×1
xcode4.2 ×1
xcode4.4 ×1