nsnull

how to remove NULL values from NSMutableArray? ios

假装没事ソ 提交于 2019-12-06 01:55:28
问题 i have array of birthdates as array is getting filled from facebook so there are some friends whos birthdates are private so it contain NULL how to convert that array like empty string wherever there is null value the array is like below "<null>", "10/29/1988", "11/13", "03/24/1987", "04/25/1990", "03/13", "01/01", "<null>", "12/15/1905", "07/10", "11/02/1990", "12/30/1990", "<null>", "07/22/1990", "01/01", "07/17/1989", "08/28/1990", "01/10/1990", "06/12/1990", 回答1: The null values appear to

how to remove NULL values from NSMutableArray? ios

风流意气都作罢 提交于 2019-12-04 06:42:24
i have array of birthdates as array is getting filled from facebook so there are some friends whos birthdates are private so it contain NULL how to convert that array like empty string wherever there is null value the array is like below "<null>", "10/29/1988", "11/13", "03/24/1987", "04/25/1990", "03/13", "01/01", "<null>", "12/15/1905", "07/10", "11/02/1990", "12/30/1990", "<null>", "07/22/1990", "01/01", "07/17/1989", "08/28/1990", "01/10/1990", "06/12/1990", The null values appear to be string literals @"<null>" rather than the NSNull objects typically used to represent nil s in Cocoa

Removing nulls from a JSON structure recursively

时光毁灭记忆、已成空白 提交于 2019-11-30 17:51:31
问题 I'm frequently finding the need to cache data structures created by NSJSONSerialization to disk and as -writeToFile fails if there are nulls, I need a fix that works when the structure is unknown. This works, and direct mutation is allowed as the instances of NSMutableDictionary themselves are not being enumerated, but it feels a bit hacky. Is this totally fine or is it absolutely necessary to recreate a new tree and return that? - (void) removeNullsFromJSONTree:(id) branch { if ([branch

Are NULL and nil equivalent?

情到浓时终转凉″ 提交于 2019-11-30 08:19:01
Actually my question here is: are null and nil equivalent or not? I have an example but I am confused when they are equal when they are not. NSNull *nullValue = [NSNull null]; NSArray *arrayWithNull = [NSArray arrayWithObject:nullValue]; NSLog(@"arrayWithNull: %@", arrayWithNull); id aValue = [arrayWithNull objectAtIndex:0]; if (aValue == nil) { NSLog(@"equals nil"); } else if (aValue == [NSNull null]) { NSLog(@"equals NSNull instance"); if ([aValue isEqual:nil]) { NSLog(@"isEqual:nil"); } } Here in the above case it shows that both null and nil are not equal and it displays "equals NSNull

How can I check if an object in an NSArray is NSNull?

戏子无情 提交于 2019-11-29 21:12:43
I am getting an array with null value. Please check the structure of my array below: ( "< null>" ) When I'm trying to access index 0 its crashing because of -[NSNull isEqualToString:]: unrecognized selector sent to instance 0x389cea70 Currently its crashing because of that array with a crash log: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull isEqualToString:]: unrecognized selector sent to instance 0x389cea70' *** First throw call stack: (0x2d9fdf53 0x3820a6af 0x2da018e7 0x2da001d3 0x2d94f598 0x1dee57 0x1dfd31 0x302f598d 0x301a03e3 0x3052aeed

Are NULL and nil equivalent?

最后都变了- 提交于 2019-11-29 11:26:07
问题 Actually my question here is: are null and nil equivalent or not? I have an example but I am confused when they are equal when they are not. NSNull *nullValue = [NSNull null]; NSArray *arrayWithNull = [NSArray arrayWithObject:nullValue]; NSLog(@"arrayWithNull: %@", arrayWithNull); id aValue = [arrayWithNull objectAtIndex:0]; if (aValue == nil) { NSLog(@"equals nil"); } else if (aValue == [NSNull null]) { NSLog(@"equals NSNull instance"); if ([aValue isEqual:nil]) { NSLog(@"isEqual:nil"); } }

ios中json解析出现的null问题

拟墨画扇 提交于 2019-11-28 22:27:40
在iOS开发过程中经常需要与服务器进行数据通讯,Json就是一种常用的高效简洁的数据格式。 问题现象 但是几个项目下来一直遇到一个坑爹的问题,程序在获取某些数据之后莫名崩溃。其实很早就发现了原因:由于服务器的数据库中有些字段为空,然后以Json形式返回给客户端时就会出现这样的数据: "somevalue":null 通过JsonKit 这个第三方库解析出来的数据就成了 somevalue = "<null>"; 这个数据类型不是nil 也不是 String。 解析成对象之后,如果直接向这个对象发送消息(eg:length,count 等等)就会直接崩溃。提示错误为: -[NSNull length]: unrecognized selector sent to instance 0x388a4a70 解决方法 其实一直没有找到完美的解决办法,坑了我很久。 1、最开始的解决方法就是为了应付当前遇到的崩溃,看看哪个字段可能为空,那么就对该字段使用前进行判断,通过崩溃时的错误提示可以看出,这样的字段解析成的对象是 NSNull 类型的,所以可以直接判断是不是此类型: if (![isKindOfClass:[NSNull class]]){xxxxxxx;} 因为字段实在太多,就找一个补一个。 2、后来想彻底解决这问题,就打算从数据源下手,其实应该可以用正则表达式匹配这个null

What is causing NSNull length unrecognized selector keyCommand error

会有一股神秘感。 提交于 2019-11-27 15:09:10
I have this class/storyboard scene in a project that up to last night worked fine for the past 4 weeks i worked on it. I have managed to comment out practically everything and I still get the crash when tapping on the UITextField and typing a number. It only crashes when I type in a value, otherwise it doesn't crash. Here is the class as I am running it now: import Foundation import UIKit import HealthKit import CoreData class WorkoutViewController: UITableViewController { //Properties @IBOutlet var numberOfLapsTextField: UITextField? @IBOutlet var metersPerLapTextField: UITextField? @IBOutlet

Replace occurrences of NSNull in nested NSDictionary

懵懂的女人 提交于 2019-11-27 09:16:37
This question is similar to this question , however this method only works on the root level of the dictionary. I'm looking to replace any occurrence of NSNull values with an empty string, so that I can save the full dictionary to a plist file (if i add it with the NSNull's the file won't write). My dictionary, however, has nested dictionaries inside it. Like this: "dictKeyName" = { innerStrKeyName = "This is a string in a dictionary"; innerNullKeyName = "<null>"; innerDictKeyName = { "innerDictStrKeyName" = "This is a string in a Dictionary in another Dictionary"; "innerDictNullKeyName" = "

Detect a Null value in NSDictionary

依然范特西╮ 提交于 2019-11-27 08:12:38
I have an NSDictionary that's populated from a JSON response from an API server. Sometimes the values for a key in this dictionary are Null I am trying to take the given value and drop it into the detail text of a table cell for display. The problem is that when I try to coerce the value into an NSString I get a crash, which I think is because I'm trying to coerce Null into a string. What's the right way to do this? What I want to do is something like this: cell.detailTextLabel.text = sensor.objectForKey( "latestValue" ) as NSString Here's an example of the Dictionary: Printing description of