我试图按照SF的建议,通过在我的构建阶段的"编译源"部分的文件的编译标志中放置"-fno-objc-arc"来关闭一个文件的每个文件的Objective-C arc对于我的项目.
这对我不起作用,因为仍然会生成与ARC相关的错误.
我在日志中看到我试图执行此操作的文件以下警告:
"clang:warning:编译期间未使用的参数:' - fno_objc_arc'"
我注意到它显示下划线而不是破折号.当我查看生成的编译行时,它还会显示下划线而不是破折号.
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c
-arch armv7 -fmessage-length=0 -std=gnu99 -fobjc-arc -Wno-trigraphs -fpascal-strings -O0
-Werror-implicit-function-declaration -Wmissing-field-initializers -Wno-missing-prototypes -Wreturn-type
-Wno-implicit-atomic-properties -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function
-Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wuninitialized -Wno-unknown-pragmas
-Wno-shadow -Wno-four-char-constants -Wno-sign-compare -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof
-Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wno-deprecated-implementations -DDEBUG=1
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk
-Wprotocol -Wdeprecated-declarations -g -Wno-conversion -Wno-sign-conversion -mthumb "-DIBOutlet=__attribute__((iboutlet))"
"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)"
-miphoneos-version-min=5.1 -iquote /x/xcode/DerivedData/myproj-eqyvffptnyujnsgcmhlqunfmfytp/Build/Intermediates/myproj.build/Debug-iphoneos/myproj.build/myproj-generated-files.hmap
-I/x/xcode/DerivedData/myproj-eqyvffptnyujnsgcmhlqunfmfytp/Build/Intermediates/myproj.build/Debug-iphoneos/myproj.build/myproj-own-target-headers.hmap
-I/x/xcode/DerivedData/myproj-eqyvffptnyujnsgcmhlqunfmfytp/Build/Intermediates/myproj.build/Debug-iphoneos/myproj.build/myproj-all-target-headers.hmap
-iquote /x/xcode/DerivedData/myproj-eqyvffptnyujnsgcmhlqunfmfytp/Build/Intermediates/myproj.build/Debug-iphoneos/Voyeur.build/myproj-project-headers.hmap
-I/x/xcode/DerivedData/myproj-eqyvffptnyujnsgcmhlqunfmfytp/Build/Products/Debug-iphoneos/include
-I/x/xcode/DerivedData/myproj-eqyvffptnyujnsgcmhlqunfmfytp/Build/Intermediates/myproj.build/Debug-iphoneos/myproj.build/DerivedSources/armv7
-I/x/xcode/DerivedData/myproj-eqyvffptnyujnsgcmhlqunfmfytp/Build/Intermediates/myproj.build/Debug-iphoneos/myproj.build/DerivedSources
-F/x/xcode/DerivedData/myproj-eqyvffptnyujnsgcmhlqunfmfytp/Build/Products/Debug-iphoneos -fno_objc_arc
-include /x/xcode/DerivedData/myproj-eqyvffptnyujnsgcmhlqunfmfytp/Build/Intermediates/PrecompiledHeaders/myproj-Prefix-adnhewmpoabuzebrrqoplkebnugj/myproj-Prefix.pch
-MMD -MT dependencies -MF /x/xcode/DerivedData/myproj-eqyvffptnyujnsgcmhlqunfmfytp/Build/Intermediates/myproj.build/Debug-iphoneos/myproj.build/Objects-normal/armv7/mySource.d
--serialize-diagnostics /x/xcode/DerivedData/myproj-eqyvffptnyujnsgcmhlqunfmfytp/Build/Intermediates/myproj.build/Debug-iphoneos/myproj.build/Objects-normal/armv7/mySource.dia
-c /x/git/myproj/subdir/mySource.m …Run Code Online (Sandbox Code Playgroud) 在启用ARC的项目中,我可以在self中使用的等效关键字是什么?例如:[self mymethod]; 什么是ARC等效的这种方法调用?
我在我的代码中使用ARC,我收到错误
Object 0x781b8e0 of class __NSCFString autoreleased with no pool in place - just leaking - break on objc_autoreleaseNoPool() to debug
Run Code Online (Sandbox Code Playgroud)
它打破的线是
return UIApplicationMain(argc, argv, nil, NSStringFromClass([HomePageAppDelegate class]));
Run Code Online (Sandbox Code Playgroud)
因为我使用ARC,所以不能NSAutoReleasePool像往常那样放置它.我可以使用什么来修复此错误?
我将SoundCloud API添加到iOS项目中,我没有使用ARC.SoundCloud代码使用
@property(nonatomic, strong, readonly) NSArray *accounts;
Run Code Online (Sandbox Code Playgroud)
我应该改变它吗?
@property(nonatomic, retain) NSArray *accounts;
Run Code Online (Sandbox Code Playgroud)
并继续使用GCC或我应该更改为LLVM编译器?
如果我采用海湾合作委员会的路线,还有什么可以改变的,我不是百分之百关于这两个选项如何影响项目?这只是上面的变化吗?
任何人都可以告诉我,我是否在ARC环境中的以下代码中正确处理内存?我担心如果我不能在ARC中使用发布/自动释放,dict对象将如何释放!我知道如果它是强类型然后它会在创建新类型之前被释放但是在下面看起来我不知道它会如何工作.
NSMutableArray *questions = [[NSMutableArray alloc] init];
for (NSDictionary *q in [delegate questions])
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setValue:[q objectForKey:@"text"] forKey:@"text"];
[dict setValue:nil forKey:@"value"];
[dict setValue:[NSString stringWithFormat:@"%d",tag] forKey:@"tag"];
[questions addObject:dict];
dict = nil;
}
Run Code Online (Sandbox Code Playgroud) 使用ARC.我有一个简单的两个viewcontroollers,一个是启动viewcontroller,第二个是自定义UIImagepickerViewController(对它有几个自定义视图)
@interface ViewController : UIViewController {
}
@property (nonatomic, strong) CameraController *cameraController;
@implementation ViewController
@synthesize cameraController;
-(void) showCame {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
self.cameraController = [[CameraController alloc] init];
self.cameraController.delegate = self;
[self presentModalViewController:self.cameraController animated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我做[self dismissModalViewControllerAnimated:YES]; 在相机控制器中,它不会释放内存,只有当我第二次调用它时,它会调用第一个实例的dealloc并创建第二个实例.
不要忘记我使用ARC
编辑:我只是用两个控制器创建空白项目,用仪器运行它(Allocations),我在应用程序完全加载后有568Kb然后我点击显示模态控制器并解雇它,我得到642Kb(在第二个视图控制器中我放了10来自IB的对象)问题是为什么?为什么这些数据没有完全被破坏,可能是缓存还是一些?
我是iphone开发的新手.我了解到ARC现在是IOS中引入的新功能.我的问题是,我有一个旧的Non ARC项目,手动发布,是否可以将此项目从非ARC切换到ARC?
谢谢,
拉吉
我正在尝试这样做:
NSString *responseDataString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];
Run Code Online (Sandbox Code Playgroud)
但在ARC中,我无法使用[NSString alloc].我不想为此文件禁用ARC,那么有没有办法在ARC中使用其他方法执行相同的操作?
在下面的代码片段中,使用ARC,我如何让委托活得足够长以调用这两个方法?
目前我收到编译器错误
接收器类型错误'__autoreleasing id*'
我假设我需要做一些事情让ARC保留委托并在完成调用时释放它但不确定正确的做法是什么.
- (BOOL) requestFromURL:(NSString*)url withDelegate:( id<SimpleDataDelegate>*) delegate
{
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://..."]]
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
if ( error )
{
[delegate gotFailure:data];
}
else
{
[delegate gotResult:data];
}
}];
return YES;
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
在xcode 4.5.1中,关于ios ARC
这是我的代码(弧形)
self.string1=@"aaa";
__weak NSString *temp= self.string1;
NSLog(@"string1 %@",self.string1);
NSLog(@"temp %@",temp);
self.string1=nil;
NSLog(@"---after self.string1 = nil----");
NSLog(@"string1 %@",self.string1);
NSLog(@"temp %@",temp);
Run Code Online (Sandbox Code Playgroud)
我认为输出应该如下:
string1 aaa
temp aaa
---after self.string1 = nil----
string1 (null)
temp (null)
Run Code Online (Sandbox Code Playgroud)
但是,当我在xcode4.5.1中运行它时,它让我感到困惑
string1 aaa
temp aaa
---after self.string1 = nil----
string1 (null)
temp aaa
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助我,并告诉我为什么temp = @"aaa"(它是__weak,在string1 = nil之后它应该是nil)
编辑:大家好.我们会以错误的方向讨论吗?也许NSLog是在核心基础功能参考中定义的.ARC对核心基础功能的参数有一些规则就像NSLog一样?我们将_weak对象作为参数传递给NSLog,它会将_weak改为_autorelease吗?
objective-c ×8
ios ×7
iphone ×4
xcode ×2
clang ×1
ios5.1 ×1
llvm ×1
release ×1
soundcloud ×1
xcode4.3 ×1