我下载了Xcode 4.2开发人员预览版,并创建了一个cocoa应用程序.但是我在委托类中发现了一个非常奇怪的语法:
@property (strong) IBOutlet NSWindow *window;
Run Code Online (Sandbox Code Playgroud)
这是什么意思?编译器甚至无法编译它.
提前致谢!
我试图解决这个问题.我知道如何让ARC项目使用不使用ARC的文件或静态库.例如,使用编译器标志-fno-objc-arc.
但是,如果我有一个不使用ARC的项目并希望包含一个用ARC编译的静态库,该怎么办?每当我想要构建项目时,它告诉我它不会识别诸如"strong,__ securefun_tareined,......"之类的东西.
我正在使用github上提供的ARCified版KeychainItemWrapper ,我无法将它存储在电子邮件和密码中.
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"myApp" accessGroup:@"MY_APP.com.yourcompany.GenericKeychainSuite"];
[keychainItem setObject:[self.email dataUsingEncoding:NSUTF8StringEncoding] forKey:(__bridge id)kSecAttrAccount];
[keychainItem setObject:self.password forKey:(__bridge id)kSecValueData];
Run Code Online (Sandbox Code Playgroud)
只要我存储一封没有符号(@)的电子邮件,我的工作就完美了.否则,我收到错误
*** Assertion failure in -[KeychainItemWrapper writeToKeychain]
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't add the Keychain Item.'
Run Code Online (Sandbox Code Playgroud)
哪些来自这些方面
result = SecItemAdd((__bridge CFDictionaryRef)[self dictionaryToSecItemFormat:keychainItemData], NULL);
NSAssert( result == noErr, @"Couldn't add the Keychain Item." );
Run Code Online (Sandbox Code Playgroud)
你对这里可能出现的问题有什么看法吗?
谢谢
使用ARC进行编译时,方法参数通常似乎保留在方法的开头并在结束时释放.这个保留/释放对似乎是多余的,并且与ARC"产生你本来会编写的代码"的想法相矛盾.在那些黑暗的,ARC之前的日子里没有人对所有方法论证进行额外的保留/释放只是为了安全起见,是吗?
考虑:
@interface Test : NSObject
@end
@implementation Test
- (void)testARC:(NSString *)s
{
[s length]; // no extra retain/release here.
}
- (void)testARC2:(NSString *)s
{
// ARC inserts [s retain]
[s length];
[s length];
// ARC inserts [s release]
}
- (void)testARC3:(__unsafe_unretained NSString *)s
{
// no retain -- we used __unsafe_unretained
[s length];
[s length];
// no release -- we used __unsafe_unretained
}
@end
Run Code Online (Sandbox Code Playgroud)
当在Xcode 4.3.2在释放模式编译的组件(例如,我很能理解它)包含到电话objc_retain和objc_release在第二个方法的开始和结束.这是怎么回事?
这不是一个大问题,但是当使用Instruments分析对性能敏感的代码时,会出现这种额外的保留/释放流量.看起来你可以装饰方法参数__unsafe_unretained以避免这种额外的保留/释放,就像我在第三个例子中所做的那样,但这样做感觉非常恶心.
我正在将部分项目转移到iOS 5/ARC.最古老的项目之一(iOS 4.2,支持iPod Touch 2g的armv6)给了我:
dyld`dyld_fatal_error:
0x8feb1070: int3
0x8feb1071: nop
Run Code Online (Sandbox Code Playgroud)
在发布图像之后,但在进入主图像之前.必须将一些lib /代码更新到iOS 5,但哪一个?是否可以使用比猜测更好的方法?
我在xcode中打开了一个新标志并收到警告"在ARC模式下弱接收器可能无法预测为空".这让我感到困惑,因为因为它可能是零.
我有这个代码,使用"__bridge"来转换颜色的ID:
CGColorRef tabColor = (5 == 5
? [UIColor blueColor].CGColor
: [UIColor greenColor].CGColor);
CGColorRef startColor = [UIColor whiteColor].CGColor;
CGColorRef endColor = tabColor;
NSArray *colors = [NSArray arrayWithObjects:(__bridge id)startColor, (__bridge id)endColor, nil];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations);
Run Code Online (Sandbox Code Playgroud)
但会:
NSArray *colors = [NSArray arrayWithObjects:(id)CFBridgingRelease(startColor), (id)CFBridgingRelease(endColor), nil];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)CFBridgingRetain(colors), locations);
Run Code Online (Sandbox Code Playgroud)
是一个更好的解决方案
cocoa-touch core-graphics objective-c ios automatic-ref-counting
编辑 - 我已将以下问题跟踪到64位与32位架构问题...请参阅我发布的答案,了解我是如何解决的
我使用SudzC为Web服务生成SOAP代码.它们为您提供了一个示例应用程序,我可以在设备和模拟器上成功使用它.
然后我开始构建我的应用程序.我使用空白应用程序模板(启用了CoreData和ARC)将SudzC生成的文件导入到新的XCode项目中.
我启动并运行了第一个SOAP请求 - 一切都在模拟器中运行 - 然后我在设备上运行我的第一个测试(运行iOS 7.02的iPhone 5S).EXC_BAD_ACCESS每次运行SOAP请求时,设备都会抛出错误.
我已将此跟踪到SoapRequest.m文件,特别是connectionDidFinishLoading方法.此方法使用objc_msgSend调用将SOAP响应数据发送回另一个类(在本例中为我的视图控制器)中的处理程序方法.这是代码:
SoapRequest.m:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSError* error;
if(self.logging == YES) {
NSString* response = [[NSString alloc] initWithData: self.receivedData encoding: NSUTF8StringEncoding];
NSLog(@"%@", response);
}
CXMLDocument* doc = [[CXMLDocument alloc] initWithData: self.receivedData options: 0 error: &error];
if(doc == nil) {
[self handleError:error];
return;
}
id output = nil;
SoapFault* fault = [SoapFault faultWithXMLDocument: doc];
if([fault hasFault]) {
if(self.action == …Run Code Online (Sandbox Code Playgroud) 我最近使用自动参考计数(ARC)开始了一个新项目.
当我分配CALayer的内容时:
UIView* view = ...
UIImage* image = ...
view.layer.contents = image.CGImage
Run Code Online (Sandbox Code Playgroud)
我收到了一个错误
使用ARC不允许将非Objective-C指针类型'CGImageRef'隐式转换为'id'
简单地铸造CGImageRef到id隐藏的错误,但我想知道如果ARC仍然正常工作呢?
core-animation core-graphics objective-c ios automatic-ref-counting
自动引用计数(ARC)引入了一些新的类型限定符.我见过__strong和__weak,但他们做什么?