gpt4 book ai didi

iphone - 如何在 iphone 中将 NSArray 数据分配给 NSMutableArray?

转载 作者:技术小花猫 更新时间:2023-10-29 11:09:17 24 4
gpt4 key购买 nike

在我的应用程序中,我有一个包含一些数据的 NSArray。我想获取该数据并将其放入名为 subArrayDataNSMutableArray 中。我能够将第一个数组中的数据插入到可变数组中,但是当应用程序运行时我得到:

warning:Incompatible pointer types assigning to 'nsmutablearray *' from 'nsarray *' please help out.

以下是我的代码:.h文件

#import <UIKit/UIKit.h>

@interface AddNew : UIViewController
{
NSMutableArray *subArrayData;;
}
@property(nonatomic ,retain)NSMutableArray *subArrayData;

.m文件

#import "AddNew.h"
#import "DashBoardPage.h"
#import "SubmitYourListing.h"


@implementation AddNew

@synthesize subArrayData;

-(void)accommodationAndTravel
{
subArrayData =[[NSArray alloc] initWithArray:[NSArray arrayWithObjects:@"Select one",@"Accommodation and travel hospitality",@"Apartments and villas",@"Bed and Breakfast",@"Caravan parks and campsites",@"Hospitality",
@"Hotels and Motels",@"Snow and Ski lodges",@"Tourist attractions and tourism information",@"Tours and Holidays",@"Travel agents and Services",nil]];


}

最佳答案

您可以通过调用其 -mutableCopy 方法将任何 NSArray 转换为 NSMutable 数组:

NSArray *someArray = ...;
NSMutableArray* subArrayData = [someArray mutableCopy];

关于iphone - 如何在 iphone 中将 NSArray 数据分配给 NSMutableArray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10204510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com