我來自C#,LINQ就像第二個本質。我有以下功能,我不知道是否可以縮短我「跳過」特殊屬性的部分?我有屬性「名稱」的數組,我想從self.attributes不包含這些名稱返回屬性列表。這是我的功能,這將是1號線在C#:(在NSMutableArray中查找項目
- (NSArray*)getDisplayedAttributes
{
//Get stop attributes
NSMutableArray *attributes = [[NSMutableArray alloc] init];
for (Attribute *attr in self.attributes)
{
// Skip special attribute
BOOL found = false;
for (Attribute *sa in @[@"D:AR",@"D:AS",@"D:ARF",@"D:DD",@"D:DH"])
{
if ([(NSString*)sa isEqualToString:attr.name])
{
found = true;
break;
}
}
if (found) continue;
Attribute *attribute = [[Attribute alloc] init];
attribute.name = attr.name;
attribute.value = attr.value;
[attributes addObject:attribute];
}
return attributes;
}
你能給一個樣本輸入和期望輸出的例子嗎? – matt