我将我的Xcode更新为4.2版本,其中包括ARC技术.这似乎是一件好事,但如果我根据Apple的建议启用ARC并编辑我的代码,我的应用程序是否可以在4.3.x设备上构建和运行?或仅适用于iOS 5的?
我正在使用这堂课:
https://github.com/alexleutgoeb/ALPickerView
由于我转换为ARC,因此在点击pickerview几次后出现此错误:
2011-10-18 14:10:19.424 MappingApp[3398:10d03] An instance 0x73c7cd0 of class CustomTapGestureRecognizer 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 0x5d93430> (<NSKeyValueObservance 0x5d933f0: Observer: 0x5d66eb0, Key path: state, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x746b180>)
Run Code Online (Sandbox Code Playgroud)
该错误指向CustomTapGestureRecoginizer类和此方法的最后一行:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { …Run Code Online (Sandbox Code Playgroud) cocoa-touch dealloc ios observer-pattern automatic-ref-counting
到目前为止,我一直在删除dealloc中的观察者(通知或KVO).由于dealloc在ARC中消失了,推荐的方法是什么?
cocoa objective-c key-value-observing nsnotifications automatic-ref-counting
我在我的应用程序中使用以下模式并转换到ARC.基本上,对象保留控制器的实例,并在通过委托协议通知它已完成时释放该控制器.我不使用iVar /属性b/c startProcess可以调用N次来处理N个东西.
示例如下:
// start a process in a controller
- (void)startProcess
{
MyController *controller = [[MyController alloc] init];
// set the delegate, the delegate is defined as (nonatomic, assign)
controller.delegate = self;
[controller start];
}
// when the delegate is notified, release the controller
- (void)myControllerDidFinish:(MyController):controller
{
// do something with results
[controller release];
}
Run Code Online (Sandbox Code Playgroud)
当上述实现转换为ARC时,在startProcess结束后不再保留控制器,因此不会发生处理并且永远不会收到委托消息.
问题:在将我的项目转换为使用ARC时,如何修改上述实现以便在实例化控制器的对象中创建iVar而无法正常工作?Apple的文档中有一个类似的例子可以转换到ARC,但它涉及使用块.我宁愿不用完成块替换委托协议.
编辑:在代码中添加注释re如何定义委托
编辑:澄清第一段解释为什么持有控制器的iVar/property不起作用
使用ARC销毁对象的正确方法是什么?
我想UIViewController在运行期间的某些时候销毁一些s以及一个持有AUGraph的对象.
目前,当我的父视图控制器创建viewcontroller对象并将其视图分配给它时view,这些对象显然与父对象保持活跃.我想在不需要的时候销毁这些子视图控制器.
可能重复:
IBOutlets在ARC下是强还是弱?
我简单地读了一下ARC并且认为好,一切都很强大,代表很弱.
现在我在界面构建器中创建一个视图并制作IBOutlets,并且Xcode的默认设置设置为弱.
似乎有这个建议的原因,是否有一个理由是大多数IBOutlets想要弱财产?
那是因为这些视图(IBOutlets)已被保留,因为它们附加到其超级视图?我们很少取代IBOutlet观点?
但是我认为将它设置为强大并没有什么害处,它有问题吗?
我目前正在使用theos构建系统为越狱的iPhone编写应用程序和调整.有没有办法让我为特定项目启用自动引用计数?
我用谷歌搜索并试图破译theos makefile,但我找不到任何东西.
在xcode中,可以给出一些Objective-C代码,以查看它将在Assembly中输出的代码.
是否可以查看给定的ARC启用代码,以查看ARC将输出的Objective-C?
当我做下面的事情时,我得到一个错误说
for (UIView* att in bottomAttachments) {
if (i <= [cells count]) {
att = [[UIView alloc] extraStuff]
}
}
Run Code Online (Sandbox Code Playgroud)
Fast Enumeration variables cannot be modified in ARC: declare __strong
我__strong该做什么以及为什么要添加它?
这两行代码之间是否存在差异?
__weak IBOutlet UITextField *usernameField;
@property (weak) IBOutlet UITextField *usernameField;
Run Code Online (Sandbox Code Playgroud)
如果在.h或.m文件的接口部分声明其中任何一个怎么办?
ios ×8
objective-c ×7
xcode ×2
cocoa ×1
cocoa-touch ×1
dealloc ×1
iboutlet ×1
iphone ×1
theos ×1
xcode4.2 ×1