标签: automatic-ref-counting

Objective-C SCNetworkReachabilityContext ARC转换

在将应用转换为使用自动引用计数时,我遇到了以下错误:

SCNetworkReachabilityContext context = {0, self, NULL, NULL, NULL};
Run Code Online (Sandbox Code Playgroud)

使用ARC不允许将Objective-C指针隐式转换为'void*'

这可以修复编译器错误,但会发出警告:

SCNetworkReachabilityContext context = {0, objc_unretainedPointer(self), NULL, NULL, NULL};
Run Code Online (Sandbox Code Playgroud)

如何摆脱这种警告?

使用类型'objc_objectptr_t'(又名'const void*')的表达式初始化'void*'会丢弃限定符

iphone objective-c ipad automatic-ref-counting

5
推荐指数
1
解决办法
2051
查看次数

ARC下的id数组成员实例

我想写这样的东西:

@interface Foo{

    __strong id idArray[]; 

}
@end
Run Code Online (Sandbox Code Playgroud)

但是编译器抱怨它:

Field has incomplete type '__strong id []'.
Run Code Online (Sandbox Code Playgroud)

如何在ARC下创建id数组成员实例?我如何初始化该数组?使用malloc?新[]?

我不想使用NSArray,因为我正在将一个大型库转换为ARC,这将导致很多工作.

objective-c automatic-ref-counting

5
推荐指数
1
解决办法
2849
查看次数

'__strong'仅适用于objective-c对象或块指针类型; 在这里键入XXX"警告

我收到许多类型的警告:

'__strong'仅适用于objective-c对象或块指针类型; 这里输入的是......

警告指向框架标题.例如NSNotification,NSURL,NSIndexset等.

它们是什么,我该如何修复它?

注1:我使用ARC

注意2:该应用程序似乎工作

编辑1:警告似乎来自我的pch文件.这是:

//
// Prefix header for all source files of the 'myapp' target in the 'myapp' project
//

#import <Availability.h>

#ifndef __IPHONE_5_0
     #warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
#endif
Run Code Online (Sandbox Code Playgroud)

编辑2:警告示例:NSString.h中的警告指向:

/* Methods to convert NSString to a NULL-terminated cString using the specified encoding.     Note, these are the "new" cString methods, and are not deprecated like the older cString     methods …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c compiler-warnings automatic-ref-counting

5
推荐指数
2
解决办法
3666
查看次数

如何正确使用__bridge的ARC

我将下面显示的代码更改为ARC兼容.

我只是像Xcode建议的那样改变它,并且它在Xcode上没有显示错误.但是一旦事件发生,代码就会崩溃.有人有想法解决这个问题吗?

我不确定这种迷恋是否因为acapela SDK而发生.

这是非ARC代码,它工作正常.

void MyInterruptionListener(void *inClientData, UInt32 inInterruptionState) {

    AcapelaSpeech* anAcapelaSpeech = *(AcapelaSpeech**)inClientData;

    if (inInterruptionState == kAudioSessionBeginInterruption) {

        [anAcapelaSpeech setActive:NO];
        status = AudioSessionSetActive(NO);
    }
    if (inInterruptionState == kAudioSessionEndInterruption) {

        status = AudioSessionSetActive(YES);
        [anAcapelaSpeech setActive:YES];
    }
}
Run Code Online (Sandbox Code Playgroud)

这是ARC兼容的,但它会破坏[anAcapelaSpeech setActive:NO] ;.

void MyInterruptionListener(void *inClientData, UInt32 inInterruptionState) {

    AcapelaSpeech* anAcapelaSpeech = (__bridge_transfer AcapelaSpeech*)inClientData;

    if (inInterruptionState == kAudioSessionBeginInterruption) {

        [anAcapelaSpeech setActive:NO];
        AudioSessionSetActive(NO);
    }
    if (inInterruptionState == kAudioSessionEndInterruption) {

        AudioSessionSetActive(YES);
        [anAcapelaSpeech setActive:YES];
    }
}
Run Code Online (Sandbox Code Playgroud)

附加信息. 我正在使用Acapela音频SDK,音频中断代码显示在此PDF的中断. http://www.ecometrixem.com/cms-assets/documents/44729-919017.acapela-for-iphone.pdf

这是暗恋的截图. 在此输入图像描述

已解决 此代码有效,谢谢.

void MyInterruptionListener(void *inClientData, …
Run Code Online (Sandbox Code Playgroud)

iphone ios automatic-ref-counting

5
推荐指数
1
解决办法
2066
查看次数

为什么这个演员不需要ARC下的桥接?

为什么将CGImageRef转换为对象指针不需要内存管理信息(__bridge等)?例如,如果image的类型为UIImage*,而layer是UIView的底层,则以下代码行不会引起编译器的任何抱怨:

layer.content = (id)[image CGImage];
Run Code Online (Sandbox Code Playgroud)

ios automatic-ref-counting

5
推荐指数
1
解决办法
185
查看次数

ARC,非ARC和继承

除了通过第三方代码强行进入项目之外,我还没有使用过ARC.我已经阅读了所有ARC文档,但没有看到这个问题的答案:

如果我有一个在编译的模块中定义的类,-fobjc-arc我可以在一个未启用ARC的模块中从中派生一个新类吗?

在我看来,只要派生类不试图触及根类中的任何ivars,它应该可以正常工作.在我看来,即使有一个dealloc方法调用[super dealloc]在派生类中也没问题.

那么,另一种方式呢?我可以从非ARC类派生一个启用ARC的类吗?应该也可以正常工作,对吧?

加分点:在混合使用ARC和非ARC代码时,有什么问题我应该让自己知道吗?

objective-c ios automatic-ref-counting

5
推荐指数
1
解决办法
1296
查看次数

如何在文件的一部分中禁用ARC,而不是整个文件?

可能重复:
显式启用ARC的Pragma?

基本上,我希望文件的一部分不使用ARC,其余的则使用它(长篇故事......).除了基于每个文件禁用ARC之外,有没有办法使用预编译器#命令执行此操作?

objective-c automatic-ref-counting

5
推荐指数
1
解决办法
847
查看次数

使用XCode将非ARC项目转换为Objective-C ARC时,Clang使用退出代码254失败

我正在尝试使用XCode ARC Converter 将非ARC项目(https://github.com/allaboutapps/A3GridTableView)转换为ARC.我收到以下错误

命令/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang失败,退出代码为254.

我按照http://maniacdev.com/2012/01/easily-get-non-arc-enabled-open-source-libraries-working-in-arc-enabled-projects/教程的方案1进行了操作.

我正在使用带有Apple LLVM编译器4.1的XCode版本4.5.2.

我试图谷歌错误,但无法将其与我的案例联系起来.提前致谢.

整个错误输出是

CompileC /Users/mihirrege/Library/Developer/Xcode/DerivedData/A3GridTableViewSample-azjqesubssdefeedzlssseklompv/Build/Intermediates/A3GridTableViewSample.build/Debug-iphonesimulator/A3GridTableViewSample.build/Objects-normal/i386/A3GridTableView.o A3GridTableView/A3GridTableView.m normal i386 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/mihirrege/Downloads/A3GridTableView-master
    setenv LANG en_US.US-ASCII
    setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch i386 -fmessage-length=0 -std=gnu99 -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type -Wno-implicit-atomic-properties -Wno-receiver-is-weak -Wduplicate-method-match -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -DDEBUG=1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.0.sdk -fexceptions -fasm-blocks -Wprotocol -Wdeprecated-declarations -Wno-sign-conversion -fobjc-abi-version=2 -fobjc-legacy-dispatch "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" …
Run Code Online (Sandbox Code Playgroud)

objective-c ios automatic-ref-counting

5
推荐指数
1
解决办法
3134
查看次数

Objective-C和ARC?使用与否?

在阅读iOS 5的一本书时,我发现了这样的信息:

"虽然ARC使您可以更轻松地编写应用程序而无需担心对象管理,但许多第三方库仍然需要手动释放对象.对于本书,所有项目都是在ARC关闭(...)的情况下创建的".

我是iOS开发的新手,我不知道如何解释它.了解iOS的内存管理似乎是非常(非常)重要的事情,但是我应该理解,ARC只是一个很好的功能,我必须在不学习它的情况下开始,因为它是如此新的,它可能不被支持或不可能在很多情况?

objective-c ios automatic-ref-counting

5
推荐指数
2
解决办法
480
查看次数

估计Cocos2d游戏的内存使用情况

我正在使用启用了ARC的Cocos2d 2.0.我的游戏是一个随机生成的游戏,所以我需要在游戏中间的场景中加载/卸载纹理(spritesheet-batchnode).我试图删除spriteframesfromfile并删除纹理为我希望在中间卸载的spritesheet键.当我在卸载工作表后使用dumpcachedtextureInfo时,spritesheet纹理不会显示在dumpcachedtextureinfo的日志中.

但是,当我使用Instruments/activity monitor来分析我的应用程序时,卸载纹理和spritesheet后,实际内存使用量不会下降.

有没有办法让dumpcachedtextureinfo不显示仍在内存中的纹理?此外,分配中的我的livebytes列显示4 MB.

另外,当我在各个地方阅读时,分配不显示纹理内存.

所以我的分配实时字节列说4 MB,我的总纹理内存如dumpcchedtextureinfo的日志显示为84MB,但内存监视器仍显示实际内存使用量为84 + Spritesheet size + Live Bytes

我无法理解这种差异?

我没有退出现场,所以我不确定ARC是拿着记忆还是什么?

memory-management instruments cocos2d-iphone automatic-ref-counting

5
推荐指数
1
解决办法
913
查看次数