文档没有说明这一点.当一个旧物体被"移走"并且一个新物体进入它的位置时,旧物体会发生什么?我必须自己发布吗?
我试图查看一个NSMutableDictionary加载NSMutableArray,我搞砸了,我不知道如何.我正在尝试加载更大的游戏问题,如果它们不是正确的级别,则删除它们.在我尝试删除之前,我没有收到错误.谁能看到这段代码中的缺陷?我非常感激!
谢谢,
〜g ^
{
NSUserDefaults *settings = [NSUserDefaults standardUserDefaults];
NSString *GameLevel = [[NSString alloc] initWithFormat: [settings objectForKey:kLevelKey]];
NSBundle *Bundle = [NSBundle mainBundle];
NSString *PListPath = [Bundle pathForResource:@"questions" ofType:@"plist"];
NSMutableDictionary *Dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:PListPath];
self.QuestionDetailsByLevel = Dictionary;
[Dictionary release];
NSMutableArray *Components = [[NSMutableArray alloc] initWithArray:[QuestionDetailsByLevel allKeys]];
self.QuestionsByLevel = Components;
int QuestionCount = [self.QuestionsByLevel count] - 1;
for (int j = 0; j < QuestionCount - 1; j++)
{
NSString *SelectedQuestion = [self.QuestionsByLevel objectAtIndex:j];
NSMutableArray *Array = [QuestionDetailsByLevel objectForKey:SelectedQuestion];
self.QDetailsByLevel …Run Code Online (Sandbox Code Playgroud) 好的:
我想从数组1中删除与数组2中的对象匹配的所有对象.
有任何想法吗?
我有NSMutableArray的NSMutableDictionary(NSString对象).NSString对象之一实际上是一个日期,我需要根据该日期对NSMutableArray进行排序,我不希望它将日期排序为字符串.我该怎么做?
我正在做最后一点内存管理整理,有些事我不明白.我已经检查了所有文档,Stack Overflow等,但仍然没有得到它.我怀疑它与数组有关.
我有一个NSMutableArray实例变量,用于保存从另一个数组中的对象创建的对象.
-viewDidLoad 按如下方式初始化数组:
self.photoAlbum = [[NSMutableArray alloc] initWithCapacity:100];
Run Code Online (Sandbox Code Playgroud)
然后它调用一个填充它们的方法.
int i = 0;
for (Gem *gem in self.entityArray) {
NSString * filePath = [[NSString alloc] initWithFormat: @"%@/%@2.jpg", [sysPaths objectAtIndex: 0], gem.detailsTitle];
// there is some stuff in here that means that there isn't a one to one relationship between the objects in gem and those in photo
Photo *photo = [[Photo alloc] init];
photo.filePath = filePath;
photo.title = gem.title;
photo.index = [NSNumber numberWithInt:i];
[self.photoAlbum addObject:photo];
[filePath …Run Code Online (Sandbox Code Playgroud) 我有这个方法处理一些我似乎无法正确的数组.与alloc和init相关的东西.
- (void)addBookmark
{
// Get the user defaults object
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
// Load your bookmarks (editable array)
NSMutableArray *bookmarks = [[NSMutableArray alloc]init];
NSArray *bookmarksLoaded = [userDefaults arrayForKey:@"bookmarks"];
if (bookmarksLoaded != nil) {
[bookmarks initWithArray:bookmarksLoaded];
} else {
[bookmarks init];
}
// Add a bookmark
NSMutableDictionary *bookmark = [NSMutableDictionary new];
[bookmark setValue:@"value" forKey:@"name"];
[bookmark setValue:@"value" forKey:@"description"];
[bookmark setValue:@"value" forKey:@"code"];
[bookmarks addObject:bookmark];
// Save your (updated) bookmarks
[userDefaults setObject:bookmarks forKey:@"bookmarks"];
[userDefaults synchronize];
// Memory cleanup
[bookmarks release];
}
Run Code Online (Sandbox Code Playgroud) 我在我的数组中添加对象时发生错误 - [__ NSArrayI addObjectsFromArray:]:无法识别的选择器发送到实例0xa0c5f70
id max;
NSMutableArray * MovePointsArray=[[NSMutableArray alloc]init];
max=[pointsArray objectAtIndex:0];
for(int i=0;i<[pointsArray count];i++){
if ([pointsArray objectAtIndex:i] > max) {
max=[pointsArray objectAtIndex:i];
[MovePointsArray addObject:max];
}
}
NSMutableArray * pointArray =[NSArray arrayWithObjects: [pointsArray objectAtIndex:0],[pointsArray lastObject], nil];
[pointArray addObjectsFromArray:MovePointsArray];
Run Code Online (Sandbox Code Playgroud)
没有得到我,我做错了.
我正在尝试对其NSMutableArray对象是类似于此的自定义类的实例进行深层复制:
@interface CustomParent : NSObject
@property NSInteger Id;
@property (strong, nonatomic) NSString *IdStr;
@property (weak, nonatomic) NSDate *Date;
@property (strong, nonatomic) NSMutableArray *CustomChildren;
@property (strong, nonatomic) CustomType *Type;
@property float Value;
@end
Run Code Online (Sandbox Code Playgroud)
我知道有很多关于复制对象的帖子,但我找不到用于获取具有集合成员或属性的对象的完整副本的示例.NSMutableArray *dstArray = [[NSMutableArray alloc] initWithArray:srcArray copyItems:YES];引发涉及该copyWithZone方法的异常.
我怎样才能做到这一点?谢谢!
var objects: AnyObject? = NSKeyedUnarchiver.unarchiveObjectWithData(data)
Run Code Online (Sandbox Code Playgroud)
如何将对象转换为NSMutableArray?我存档了NSMutableArray.
我通过componentsSeparatedByString将字符串转换为数组。它返回数组完美。但是当string为空时,返回1个对象。
为什么会这样?
NSMutableArray *imagesList=[[[productDetail objectForKey:@"productImage"] componentsSeparatedByString:@","]mutableCopy];
Run Code Online (Sandbox Code Playgroud) nsmutablearray ×10
ios ×5
objective-c ×5
iphone ×4
cocoa ×2
cocoa-touch ×2
deep-copy ×1
duplicates ×1
nsarray ×1
sorting ×1
swift ×1
uikit ×1