ios – NSArray中的NSMutableArray

我有以下代码,我想使用NSMutable数组,而不是NSArray
你可以告诉我如何加载NSMutable数组,因为当前的方法不起作用.
-(void) whatever{
NSData *htmlData = [[Nsstring stringWithContentsOfURL:[NSURL URLWithString: @"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *titles  = [xpathParser search:@"//h3"]; // get the page title - this is xpath     notation
TFHppleElement *title = [titles objectAtIndex:0];
Nsstring *myTitles = [title content];

NSArray *articles  = [xpathParser search:@"//h4"]; // get the page article - this is xpath     notation
TFHppleElement *article = [articles objectAtIndex:0];
Nsstring *myArtical = [article content];

我努力了 :

NSMutableArray *titles  = [xpathParser search:@"//h3"];

但它确实加载值?

解决方法

您可以在NSArray对象上调用mutablecopy以返回给您一个NSMutableArray.

请注意,被调用者将获得该对象的所有权,因为方法名称包含“副本”.

(Apple’s memory management guide指出,包含“alloc”,“new”或“copy”这个词的方法名称应该按照惯例返回一个您拥有的对象,因此必须放弃在某一时刻的所有权.

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...