我正在尝试将我的代码转换为Objective-C ARC并获得多个错误.
1:
NSBezierPath *path = [NSBezierPath bezierPath];
CGPathApply(pathRef, path, CGPathCallback); //error
Run Code Online (Sandbox Code Playgroud)
它说:使用ARC不允许将Objective.C指针隐式转换为'void*'
2:
static void CGPathCallback(void *info, const CGPathElement *element) {
NSBezierPath *path = info; //error
[…] }
Run Code Online (Sandbox Code Playgroud)
它说:ARC不允许将非Objective-C指针类型'void*'隐式转换为'NSBezierPath*'
任何想法,我如何解决问题?
我要做的是为每个UIButton创建的函数设置一个函数,并使用函数内部的开关来确定其行为.我在按钮上设置标签以使用开关,但它实际上并没有那么远.
for var(int i = 0; i < numResults; i++)
{
UIButton* button = [[UIButton] alloc] initWithFrame:CGRectMake(0,(i*55)+10,320,50)];
[buttton setTag:i];
[button addTarget:self action:@selector(buttonHandler) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
...
-(void) buttonHandler:(id)sender
{
//Handle the button press
}
Run Code Online (Sandbox Code Playgroud)
当我点击任何按钮时,应用程序会抛出一个错误:
- [WatchViewController buttonHandler]:无法识别的选择器发送到实例0x6845430
我相信这是因为创建了按钮变量,然后由于没有对它的引用,由ARC自动释放,因此在调用该函数时它不再存在.不幸的是,我不知道如何保持对内存中每个按钮的引用.
如果我错了(或者我写的任何东西都是不好的做法),请随时告诉我 - 它会帮助我学习!
memory-management objective-c ios ios5 automatic-ref-counting
我有一个UIViewController,UITableView作为子视图.单击某个单元格时,应显示UIImagePickerController.由于它需要很长的初始化时间,因此当UIViewController出现时,我在后台执行此过程.
现在我将ARC添加到我的项目中,然后它仍然无法正常工作.用户界面被初始流程冻结了.
这是我的代码.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelectorInBackground:@selector(initImagePickerControllerInBackground) withObject:nil];
}
...
- (void)initImagePickerController
{
if (imagePickerController != nil)
return;
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.allowsEditing = YES;
imagePickerController.delegate = self;
imagePickerController.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
}
- (void)initImagePickerControllerInBackground
{
@autoreleasepool
{
[self initImagePickerController];
}
}
Run Code Online (Sandbox Code Playgroud)
为了让它适合我,我应该改变什么?
user-interface xcode uiimagepickercontroller ios automatic-ref-counting
我最近为我的应用项目切换到ARC.我正在使用iOS 5 SDK.运行一台iPod 4g设备我没有收到任何警告.但是试图在iPod 2g上运行我的应用程序我收到很多警告:
*** __NSAutoreleaseNoPool(): Object 0x258070 of class DataModel autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x2530a0 of class __NSArrayM autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x25a2e0 of class NSCFNumber autoreleased with no pool in place - just leaking
Run Code Online (Sandbox Code Playgroud)
我想使用ARC运行arm6/arm7代码之间存在差异.
如何解决这个问题?谢谢
我需要知道我是否正确地做到了.应用程序运行正常但我不确定我的生命周期是否正确(泄漏?).
注意:仪器看不到泄漏.
方法aaa的代码:某些类A的代码:
- (void) aaa {
NSString *path = ...something...;
NSBlockOperation* theOp = [NSBlockOperation blockOperationWithBlock: ^{
// using path
[self somethingElseWith:path];
}];
[self.aQueue addOperation:theOp];
}
Run Code Online (Sandbox Code Playgroud)
所以我创建了一个块来放置aQueue(NSOperationQueue*).目标是从主线程中卸载长时间运行的somethingElseWith:方法,以便GUI继续响应.
在块内部,我引用了aaa:方法末尾超出范围的本地var"path".
如果我正确地阅读了文档,那么该块将在'path'上保留.但ARC是否隐含地在此块的末尾插入了一个版本?这将是合乎逻辑和美好的.
或者我应该将'path'声明为__block并在块的末尾将其指定为nil?(手册...)
我不确定我是否理解如何在此上下文中使用__weak.
cocoa cocoa-touch objective-c objective-c-blocks automatic-ref-counting
嘿我以前使用过解析器但从未在ARC环境中使用过.现在,当我尝试将解析器设置为self时,它会给出一条错误消息,然后不会解析我的数据.任何人都知道问题是什么以及如何解决?
这是我尝试将解析器委托设置为self时得到的警告:
Semantic Issue: Sending 'CharityController *const __strong' to parameter of incompatible type 'id<NSXMLParserDelegate>'
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
if (connection == theConnection)
{
// do something with the data object.
//NSLog(@"Data from server is: %@",data);
NSString *test = [[NSString alloc]initWithData:data encoding:NSStringEncodingConversionAllowLossy];
NSLog(@"Data from server is: %@",test);
parser = [[NSXMLParser alloc] initWithData: data];
[parser setDelegate:self];
[parser parse];
}
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"root"]) {
currentStringValue = nil; …Run Code Online (Sandbox Code Playgroud) 在ARC下,我知道"堆栈变量是用nil初始化的"(docs).静态const数组的值怎么样?这是有道理的,但我找不到官方陈述的东西.例如:
static NSString * const strings[5] = {
[2] = @"value2",
[4] = @"value3",
};
Run Code Online (Sandbox Code Playgroud)
会strings[3]== nil?
ARC代表自动参考计数.
我刚刚升级了我的项目以使用ARC.不是全部.一些.
我怎么知道?
我在目标c中编写了一个iOS程序,我需要一个具有以下特征的数组:
1)它的形状需要在运行时决定.
2)它需要能够作为属性或全局存储在objective-c类中
3)当我在特定索引处插入对象时,它需要保留在该索引处. 例如,如果我在索引5处插入,则对象需要覆盖索引5处的任何内容,并且不会移动此元素或任何其他元素(类似于java数组的工作方式)
我看过NSMutableArray,但这似乎不符合我上面描述的内容,因为它在插入时会移动元素.我也尝试了NSString *myArray = malloc(10 * sizeof(NSString *));但是这给了我一个关于需要桥接演员的错误.我不知道那是什么.
我正在使用ARC,以防万一.
我正在尝试将我的iOS项目升级为使用ARC.通过编辑 - >重构 - >转换为Objective-C ARC开始转换时,我选择我的目标,取消选择链接库并按检查.接下来我收到以下错误:
clang: error: argument unused during compilation: '-ccc-arcmt-check'
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1
Run Code Online (Sandbox Code Playgroud)
有些想法如何解决这个问题?Xcode甚至没有尝试开始转换源文件.
请注意,我的项目文件中有几个目标共享一些源文件.转换对话框仅显示当前方案中的目标集.
我已经成功转换了另一个(静态库)项目,因此Xcode设置应该没问题.
编辑:我已经激活了Xcode首选项中的错误后继续构建,至少现在我看到所有ARC错误.让我们看看这是否允许我转换为ARC.
EDIT2:我得到这个错误我的目标的每一个源文件,我不希望使用ARC的-这样看来,如果编译器并发标志问题-CCC-arcmt检查和-fno-objc弧.