在我的应用程序中,我有一个包含一些数据的 NSArray。我想获取该数据并将其放入名为 subArrayData
的 NSMutableArray
中。我能够将第一个数组中的数据插入到可变数组中,但是当应用程序运行时我得到:
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/