반응형
NULL 및 빈 문자열을 테스트하는 NSPredicate
나는 NSArray
null이거나 오히려 ''(빈 문자열)이있는 모든 문자열을 필터링해야합니다. 어떻게하나요? 나는 시도했다 :
NSPredicate *predicateName = [NSPredicate predicateWithFormat:@"(name!=nil)"];
그러나 그것은 작동하지 않는 것 같습니다. 아니면 그럴 수도 있지만 다른 종류의 null이 있습니다.
Core Data를 사용하지 않는 경우 다음을 수행 할 수 있습니다.
NSPredicate *predicateName = [NSPredicate predicateWithFormat:@"name.length > 0"];
문자열이 비어 있으면 실패합니다 (때문에 0 == 0
). 경우 마찬가지로 name
이며 nil
, 또한 실패 때문에 것입니다 [nil length] == 0
.
나는 이것이 효과가 있다고 생각한다.
NSPredicate *predicateName = [NSPredicate predicateWithFormat:@"name!=nil AND name!=''"];
NSPredicate *predicateName = [NSPredicate predicateWithFormat:@"name!=NULL"];
이 술어는 나를 위해 일했습니다.
[NSPredicate predicateWithFormat:@"(%K== nil) OR %K.length == 0", @"imageUrl", @"imageUrl"]
참고 URL : https://stackoverflow.com/questions/7369390/nspredicate-to-test-for-null-and-blank-strings
반응형
'programing' 카테고리의 다른 글
postgres를 사용하여 string_agg에서와 같이 array_agg에서 null 값을 제외하는 방법은 무엇입니까? (0) | 2020.10.25 |
---|---|
v2 Android지도의지도 중심을 얻는 방법은 무엇입니까? (0) | 2020.10.25 |
Android Studio-기기가 연결되었지만 '오프라인' (0) | 2020.10.25 |
Entity Framework-람다식이 대리자 형식이 아니기 때문에 '문자열'형식으로 변환 할 수 없습니다. (0) | 2020.10.25 |
Mac + virtualenv + pip + postgresql = 오류 : pg_config 실행 파일을 찾을 수 없음 (0) | 2020.10.25 |