2017-12-12 6 views
1

문자열이 내 tableview 셀에 있습니다. 이제 해당 문자열이 특정 배열에 있는지 확인하고 싶습니다. 그리고 그 배열에 문자열이 있다면 그 배열에서 문자열을 지우고 싶습니다. 이것은 내가 그것을 위해 노력했다 것입니다 ... Coredata 유형의 배열 필터링

또한 아래 favMessages는 coredata 객체의 배열 내가 알아낼 수 아니에요을 해결할 수있는 방법

FavoritedMessages라고합니다 .. .

당신이 이렇게 할 수
+0

다음 코드에서 StringValue 대신 속성 이름을 작성하십시오. favMessages = favMessages.filter {$ 0.StringValue! = textInCell} –

+0

favMessages 배열에 저장된 객체는 무엇입니까? –

+0

특정 배열이란 무엇입니까? –

답변

0

대신 속성 이름을 쓰기 follo의 StringValue 날개 코드.

favMessages = favMessages.filter{$0.StringValue != textInCell} 
0

, 귀하의 경우에는

favMessages = favMessages.filter({$0["Your key name of database"] as! String != "string to be compared"}) 

,

제거

var strings = ["a", "b", "c", "d"] 

요소 :

희망이

0

당신은 문자열 배열을 가지고하는 데 도움이

var firstElement = "a" 
var secondElement = "e" 

print("Before removing: ", strings) 
//Before removing: ["a", "b", "c", "d"] 

[firstElement, secondElement].forEach { 
    if let index = strings.index(of: $0) { 
     strings.remove(at: index) 
    } 
} 

결과 :

print("After removing: ", strings) 
After removing: ["b", "c", "d"]