从使用a动态构建数组的方法返回NSArray(或NSDictionary等)NSMutableArray时,使用ARC时执行此操作并避免随机内存泄漏的标准方法是什么?
例如,假设我们有一些带有名称列表的类,我们想手动过滤并获取以给定字母开头的所有名称:
- (NSArray *)getNamesByFirstLetter:(NSString *)firstLetter
{
NSMutableArray *returnValue = [[NSMutableArray alloc] init];
for(id item in self.names)
{
if([item hasPrefix:firstLetter])
{
[returnValue addObject:item];
}
}
return returnValue; // just return the above array
}
Run Code Online (Sandbox Code Playgroud)
在返回值时,我可以想到四种可能的方法:
NSMutableArray直接退货(如上)
return returnValue;
Run Code Online (Sandbox Code Playgroud)回来一个 copy
return [returnValue copy];
Run Code Online (Sandbox Code Playgroud)返回使用NSArray arrayWithArray:
return [NSArray arrayWithArray:returnValue];
Run Code Online (Sandbox Code Playgroud)创建一个NSArray,手动设置NSMutableArray为nil:
NSArray *temp = [NSArray arrayWithArray:returnValue]; // could use [returnValue copy] here too
returnValue = nil;
return …Run Code Online (Sandbox Code Playgroud)我有这个嵌套的if else条件.我想要的检查流程在下面的代码中描述.
if (HiringManagerAPPROVED)
{
//email reporting gropu
}
else if (ReportingGroupAPPROVED)
{
//email Hiringmanager
}
else if (HiringManagerReAPPROVED)
{
//email PPO
} }
else if (PpoAPPROVED)
{
//email Finance
}
else if (FinanceAPPROVED)
{
//email president & COO
}
else if (PresidentCooAPPROVED)
{
//email hr
}
else if (HRAPPROVED)
{
//email Hiring Manager
}
Run Code Online (Sandbox Code Playgroud)
如何减少支票数量,保持支票流量不变.
我按照本文所述为Azure设置blob索引和全文搜索:使用Azure搜索在Azure Blob存储中索引文档.
我的一些文档在索引器中失败,导致返回以下错误:
字段"内容"包含的字词太大而无法处理.UTF-8编码术语的最大长度为32766字节.导致此错误的最可能原因是在此字段上启用了筛选,排序和/或分面,这会导致整个字段值被索引为单个术语.请避免在大字段中使用这些选项.
产生此错误的特定pdf是3.68 MB,包含各种内容(文本,表格,图像等).
索引和索引器的设置与该文章中描述的完全相同,但增加了一些文件类型限制.
指数:
{
"name": "my-index",
"fields": [{
"name": "id",
"type": "Edm.String",
"key": true,
"searchable": false
}, {
"name": "content",
"type": "Edm.String",
"searchable": true
}]
}
Run Code Online (Sandbox Code Playgroud)
索引:
{
"name": "my-indexer",
"dataSourceName": "my-data-source",
"targetIndexName": "my-index",
"schedule": {
"interval": "PT2H"
},
"parameters": {
"maxFailedItems": 10,
"configuration": {
"indexedFileNameExtensions": ".pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.html,.xml,.eml,.msg,.txt,.text"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试搜索他们的文档和其他一些相关文章,但我找不到任何信息.我猜这是因为此功能仍在预览中.