我有一段代码对 NSMutableArray 点进行排序,如下所示:
[points sortUsingComparator:^NSComparisonResult (id firstObject, id secondObject)
{
CGPoint firstPoint = [firstObject CGPointValue];
CGPoint secondPoint = [secondObject CGPointValue];
return firstPoint.y>secondPoint.y;
}];
Run Code Online (Sandbox Code Playgroud)
这在我的第一个项目中效果非常好。然后我尝试在另一个项目中使用它,在那里我基本上复制了整个类(为了分成单独的演示项目)。在第二个项目中,Xcode 无法构建并出现以下错误:
无法使用“bool”类型的右值初始化“NSComparisonResult”类型的返回对象。
奇怪的是,如果我将代码放在新项目中的不同类中,而不是放在我的原始类“Classname.mm”中,它就会编译。.mm 与原始项目中的相同,并且包含所有相同的标头和变量。
这两个项目都是在 Xcode 5.0.1 上针对 iOS 7.0 编译的。
有谁知道为什么这种情况只会发生在我的新项目中的一堂课上?
谢谢
我想将以下字符串转换为 NSMuableArray。
var components: String = "library/book/science"
Run Code Online (Sandbox Code Playgroud)
例如,我想在 Swift 中执行以下目标 c 代码
NSArray *componentsArray = [@"library/book/science" componentsSeparatedByString:@"/"];
NSMutableArray *componentsMutableArray = [[NSMutableArray alloc] initWithArray:componentsArray];
[componentsMutableArray addObject:@"astronomy"];
Run Code Online (Sandbox Code Playgroud) 我的目标是在数组中添加一个字符串,我在一个我调用的方法中这样做.
在这个方法中,我在数组中得到一个空值,不知道为什么.我在课程开始时就有这个:
NSMutableArray *listOfEvents;
Run Code Online (Sandbox Code Playgroud)
以及我在每个事件上调用的方法:
-(void)EventList
{
[listOfEvents addObject:@"ran"];
NSLog(@"%@", listOfEvents);
}
Run Code Online (Sandbox Code Playgroud)
我进入(null)了日志.
如果我将数组定义 NSMutableArray *listOfEvents;放在函数体中,@"ran"每次都得到字符串值,因此数组总是只有一个值,而不是有多个字符串命名@"ran".
这有什么问题?似乎我无法理解有关数组的东西,尽管我已多次阅读过这些文档.
我在我的数组中有重复,我想摆脱它们,所以我运行这个循环,但它不起作用.谁知道为什么?该阵列目前有3个项目,2个重复项和1个唯一项.
for (int x = 0; x <= [array count]; x++) {
if(x > 0){
if([[array objectAtIndex:x - 1] isEqualToString:[array objectAtIndex:x]]){
[array removeObjectAtIndex:x];
}
}
}
Run Code Online (Sandbox Code Playgroud) 昨天我遇到了一个名为'收集被点名时被突变'的异常并看到了一些解决方案.我有另一个想法.如果我设置一个名为'lock'的参数,每次我枚举我锁定它然后在枚举后解锁它.Every时间我会操作它,如枚举或添加对象,我先锁定它然后在操作后解锁它.有人能告诉我它是否有效?
我有一个NSMutableArray.当我使用时NSLog,这是输出:
2012-12-15 17:58:28.849 Splash-it[504:907] (
"Open House New York",
"Boston Athletic Association",
"Autofest Tanzania"
),
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到NSString这些标题中的一个(考虑到标题会改变,我想我需要使用objectAtIndex但我不认为它会在这种情况下起作用)?
例如
NSString = @"Boston Athletic Association"
Run Code Online (Sandbox Code Playgroud) 我查看了以下资源: NSDictionary到NSArray? https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html https://developer.apple.com/library/mac/documentation/Cocoa/Reference /Foundation/Classes/NSDictionary_Class/Reference/Reference.html
我试图做的是将NSDictionary插入NSMutableArray.
相关代码对我来说似乎是这样的:
@property (strong,nonatomic) NSMutableArray * curveList;
@property (strong,nonatomic) UIBezierPath * curPath;
@property (strong, nonatomic) UIColor * curColor;
// some code to set curPath and curColor
@{@"path":_curPath, @"color":_curColor}
//how to insert this into self.curveList???
Run Code Online (Sandbox Code Playgroud) 我有一个有日期的数组.我想将数组转换为NSDate.然后转换的NSDate存储在另一个数组中.这是我的数组.
uniqueItems (
"2015-02-17",
"2015-02-09",
"2015-02-02",
"2015-01-27",
"2015-01-19",
"2015-01-12"
)
Run Code Online (Sandbox Code Playgroud)
如何将此数组转换为NSDate,并存储到另一个数组.帮我编码.
我简单地填充收到此错误NSMutableArray中TableView的cell中突出显示的代码行.
而第一行正在执行.我尝试BooksDataForTable[a]从第1行到第2行而不是BookAuthors[a]成功执行.但是在查看调试区域时我得到了一些有趣的东西.这里是.
您可以看到两者之间的差异,NSMutableArray以及错误的原因.实际上BooksDataForTable是由NSStrings BooksAuthors填充,NSArray而不幸的是我不能理解为什么它可能是这个错误背后的原因!
nsmutablearray ×10
ios ×8
objective-c ×8
xcode ×4
nsarray ×3
cgpoint ×1
cocoa ×1
duplicates ×1
exception ×1
iphone ×1
nsdate ×1
nsdictionary ×1
sorting ×1
swift ×1