如果我使用NSManagedObjectContext
在主线程上创建NSMainQueueConcurrencyType
,则必须对所有performBlock()
和save
方法使用performFetch
方法。 IE可以执行以下操作:
do {
managedObjectContext.save()
} catch let error as NSError {
print(error)
}
或者我应该总是这样做:
managedObjectContext.performBlock({
do {
managedObjectContext.save()
} catch let error as NSError {
print(error)
}
})
如果我正确理解文档,我总是必须使用performBlock()
或performBlockAndWait()
,但在XCode 7的模板代码中,他们不使用块。任何帮助表示赞赏!
答案 0 :(得分:1)
如果您已经在主线程上且有myc <-c("A,B,D","C,A,E,B","F,B")
myc <-strsplit(myc,",") #split value on comma
res <-lapply(myc,combn,2,simplify = FALSE) #create cominations
out <-matrix(unlist(res),ncol=2,byrow=TRUE) #create dataframe of combinations
out[colSums(apply(out,1,match,"B"),na.rm=TRUE)==1,] #keep only combinations with "B"
[,1] [,2]
[1,] "A" "B"
[2,] "B" "D"
[3,] "C" "B"
[4,] "A" "B"
[5,] "E" "B"
[6,] "F" "B"
上下文,则不需要使用NSMainQueueConcurrencyType
。