Tag: automatic ref counting

如何从弱财产中清除KVO?

我有一个视图(我们称之为视图A),它的超级视图(视图B)具有weak属性。 查看一个KVO的超级视图,查看B.因为视图A对视图B的引用是一个弱属性(为了防止保留周期),我怎样才能删除观察者(A观察B)? 查看A的视图B的引用在我有机会删除它之前没有被删除。 因为视图控制器有一个强烈的参考A.这里是泄漏的日志消息: An instance 0x9ac5200 of class UITableView was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info: <NSKeyValueObservationInfo 0x8660360> ( <NSKeyValueObservance […]

ARC – __unsafe_unretained的含义?

只是想确保我说得对: 我是否需要__unsafe_unretain我不拥有的对象? 如果一个对象是__unsafe_unretained我是否需要在@property使用assign ? 这是否意味着对象不被保留,只是指向我分配的对象? 我何时想使用它,除了代表? 这是一个ARC的事情还是之前使用?

无法在Mac上使用ARC的respondsToSelector

在ARC环境中调用respondsToSelector ,出现以下错误消息Automatic Reference Counting Issue No known instance method for selector respondsToSelector: 这是标题 #import <AppKit/AppKit.h> @class MTScrollView; @protocol MTScrollViewDelegate -(void)scrollViewDidScroll:(MTScrollView *)scrollView; @end @interface MTScrollView : NSScrollView { } @property(nonatomic, weak) id<MTScrollViewDelegate>delegate; @end 这是执行文件 #import "MTScrollView.h" @implementation MTScrollView @synthesize delegate; – (void)reflectScrolledClipView:(NSClipView *)aClipView { [super reflectScrolledClipView:aClipView]; if([delegate respondsToSelector:@selector(scrollViewDidScroll:)]) { [delegate scrollViewDidScroll:self]; } } @end 任何build议,为什么我得到这个错误?

语义问题:属性的合成getter遵循Cocoa命名约定来返回“拥有”的对象

我目前正在使用iOS 5 SDK试图开发我的应用程序。 我试图做一个NSString属性,然后在.m文件中进行综合(我之前完成了这个任务没有问题)。 现在,我遇到了这个问题:“语义问题:属性的合成getter遵循Cocoa命名约定来返回”拥有的“对象。 这是我的代码:.h @interface ViewController : UIViewController { NSString *newTitle; } @property (strong, nonatomic) NSString *newTitle; .M @synthesize newTitle; 有没有人有一个线索,我可以解决这个问题? 谢谢!!

弱引用的NSArray(__unsafe_unretained)到ARC下的对象

我需要将弱引用存储到NSArray中的对象,以防止保留周期。 我不确定使用正确的语法。 这是正确的方法吗? Foo* foo1 = [[Foo alloc] init]; Foo* foo2 = [[Foo alloc] init]; __unsafe_unretained Foo* weakFoo1 = foo1; __unsafe_unretained Foo* weakFoo2 = foo2; NSArray* someArray = [NSArray arrayWithObjects:weakFoo1, weakFoo2, nil]; 请注意,我需要支持iOS 4.x ,因此__unsafe_unretained而不是__weak 。 编辑 (2015-02-18): 对于那些想要使用真正的__weak指针(而不是__unsafe_unretained ),请检查出这个问题,而不是: ARC

在这个区块强烈地捕获自我很可能会导致一个保留周期

我怎样才能避免在xcode这个警告。 这里是代码片段: [player(AVPlayer object) addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(0.1, 100) queue:nil usingBlock:^(CMTime time) { current+=1; if(current==60) { min+=(current/60); current = 0; } [timerDisp(UILabel) setText:[NSString stringWithFormat:@"%02d:%02d",min,current]];///warning occurs in this line }];