将项目转换为使用ARC时,"切换案例是否在受保护的范围内"是什么意思?我正在转换一个项目使用ARC,使用Xcode 4编辑 - >重构 - >转换为Objective-C ARC ...我得到的一个错误是"切换案例在受保护的范围内"的"部分"交换机开关盒.
编辑,这是代码:
ERROR标记在"默认"情况下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"";
UITableViewCell *cell ;
switch (tableView.tag) {
case 1:
CellIdentifier = @"CellAuthor";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [[prefQueries objectAtIndex:[indexPath row]] valueForKey:@"queryString"];
break;
case 2:
CellIdentifier = @"CellJournal";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [[prefJournals …Run Code Online (Sandbox Code Playgroud) 我有一个视图(我们称之为视图A),weak它的超级视图具有属性(视图B).查看KVO的超视图,视图B.由于视图A对视图B的引用是弱属性(为了防止保留周期),如何移除观察者(A观察B)?在我有机会删除之前,查看A对视图B的引用已经过了.
由于视图控制器具有对A的强引用,因此B比B更长.这是泄漏的日志消息:
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 0x8660320: Observer: 0x8660020, Key path: contentOffset, Options: <New: YES, Old: NO, Prior: NO> Context: 0x8660020, Property: 0x864ac80>
)
Run Code Online (Sandbox Code Playgroud)
B是UITableView.设置断点会NSKVODeallocateBreak产生无用的结果.
在A的removeFromSuperview,我尝试删除观察者但是A对B参考已经nil …
我试图找出一种方法来typeof创建一个弱的引用,self以便在块中使用,以避免保留周期.
当我第一次读到这个时,似乎是使用惯例__block typeof(self) bself = self;,编译但是使用__block以避免保留周期不再起作用而__weak应该使用.
但是会__weak typeof(self) bself = self;导致错误:
类型'typeof(self)'(又名'TUAccountsViewController*const __strong')已经设置了保留属性
有没有办法使用typeof或其他调用一般创建一个弱引用self?
cocoa weak-references objective-c objective-c-blocks automatic-ref-counting
我想知道我的Xcode iPhone项目是否正在使用ARC,我不记得在创建项目时是否勾选了该框.
我怎样才能获得这些信息?
这是我第一次摆弄iOS5和ARC.到目前为止,这么好,它有效,但我遇到了某种问题.
我有一个自定义UIStoryboardSegue,我使用Facebook Connect(或其他服务)将用户登录到我的应用程序.简而言之,它应该做到以下几点:
相反,是登录开始,但是在有机会完成之前,ARC会立即释放segue.
我想到了一个快速的黑客来阻止这个:
@interface BSLoginSegue() {
__strong BSLoginSegue *_retained_self;
}
@end
// Stuff...
// Other stuff...
- (void) perform {
login();
_retained_self = self;
}
- (void) loginServiceDidSucceed:(BSLoginService *)svc {
...
_retained_self = nil;
}
Run Code Online (Sandbox Code Playgroud)
问题是,它真的是一个黑客,所以我想知道是否还有其他更优雅的方式我可以做同样的事情?
我想知道是否有人使用SFHFKeychainUtils设法修改它们以兼容ARC.更确切地说
NSDictionary *attributeResult = NULL;
NSMutableDictionary *attributeQuery = [query mutableCopy];
[attributeQuery setObject: (id) kCFBooleanTrue forKey:(__bridge id) kSecReturnAttributes];
OSStatus status = SecItemCopyMatching((CFDictionaryRef) attributeQuery,(CFTypeRef *)(attributeResult));
Run Code Online (Sandbox Code Playgroud)
我试过了
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef) attributeQuery,(CFTypeRef *)(attributeResult));
Run Code Online (Sandbox Code Playgroud)
也
CFTypeRef subAttributeResult = (CFTypeRef *)(objc_unretainedPointer(attributeResult));
OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef) attributeQuery,(CFTypeRef *)(subAttributeResult));
Run Code Online (Sandbox Code Playgroud)
这2个是我设法得到的唯一两种方法没有错误.通过在这里添加objc_XXX而不是CFTypeRef来实现任何其他方法并且在那里得到错误(从ARC中禁止从obj-c指针到CFTypeRef的隐式转换,将x参数传递给y参数丢弃限定符).显然,第一段代码也会出错.虽然构建时没有出现任何错误,但在到达此部分代码时,应用程序会因EXC_BAD_ACCESS而崩溃.
完整SFHFKeychainUtils的链接:https://github.com/ldandersen/scifihifi-iphone/tree/master/security
有什么帮助吗?谢谢.
iphone keychain ios automatic-ref-counting sfhfkeychainutils
现在我已升级到Lion和Xcode 4.3.x,调试器正在进入ARC的东西.所以我看到一个充满了屏幕
libobjc.A.dylib`objc_retainAutoreleasedReturnValue:
0x1de7fe0: pushl %ebp
Run Code Online (Sandbox Code Playgroud)
和pushl和movl和subl等可惜我不能symbolicate这些,我也不关心调试苹果的东西.有没有办法让调试器只关注我实际拥有的代码?
我正在使用LLDB,但GDB也是如此.
编辑:这也发生在AppCode上,它说了些什么(但我不知道是什么).
我尝试在其中创建一个包含类的结构,如:
struct my_struct
{
NSString *string;
// more fields
};
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,Objective-C++允许启用ARC.
它将如何管理字符串?
它可以很容易地保留在每个任务中,但释放是问题所在.
它可以添加一个带有释放的析构函数,但这会使结构变得非常简单.
它也可以使这不保留或释放,但这样做应该是unsafe_unretained.
根据我的观察,使用它时没有任何事情会崩溃,但我想知道这里到底发生了什么.
当我在ARC模式下在CoreData中为我的实体创建模型对象时,它会生成retain而不是strong.那么保留工作并在ARC模式下编译也是如此?我认为在ARC模式下我们不能使用release,autorelease和retain关键字?
就像一个doop我已经在接口.h文件中声明了Instant Variables(iVar)然后@property一段时间了.
@interface MainGameViewController : UIViewController {
UserFactorsViewController *userFactorsViewController;
UITableView *myTableView;
}
@property (nonatomic, retain) UserFactorsViewController *userFactorsViewController;
@property (nonatomic, retain) IBOutlet UITableView *myTableView;
Run Code Online (Sandbox Code Playgroud)
在自动引用计数下,我应该省去iVar并全部使用@property吗?我是否应该在财产中使用"保留"一词?如果我正在部署iOS 4.3,我还应该使用ARC吗?