ios - How can I simplify this code (conversion to NSDictionary)? -
i want convert response nsdictionary
. response implementation of alregistrationresponse
(https://github.com/applozic/applozic-chat-ios-framework/blob/master/applozic/domainclasses/alregistrationresponse.m).
nsdictionary *_response = @ { @"message":[response message] != nil ? [response message] : [nsnull null], @"devicekey":[response devicekey] != nil ? [response devicekey] : [nsnull null], @"userkey":[response userkey] != nil ? [response userkey] : [nsnull null], @"contactnumber":[response contactnumber] != nil ? [response contactnumber] : [nsnull null], @"lastsynctime":[response lastsynctime] != nil ? [response lastsynctime] : [nsnull null], @"currenttimestamp":[response currenttimestamp] != nil ? [response currenttimestamp] : [nsnull null], @"brokerurl":[response brokerurl] != nil ? [response brokerurl] : [nsnull null], @"imagelink":[response imagelink] != nil ? [response imagelink] : [nsnull null], @"statusmessage":[response statusmessage] != nil ? [response statusmessage] : [nsnull null], @"encryptionkey":[response encryptionkey] != nil ? [response encryptionkey] : [nsnull null], @"displayname":[response displayname] != nil ? [response displayname] : [nsnull null], @"notificationsoundfilename":[response notificationsoundfilename] != nil ? [response notificationsoundfilename] : [nsnull null] };
at least bit cleaner following syntax:
nsdictionary *_response = @{ @"message": [response message] ?: [nsnull null], @"devicekey": [response devicekey] ?: [nsnull null], @"userkey": [response userkey] ?: [nsnull null], @"contactnumber": [response contactnumber] ?: [nsnull null], @"lastsynctime": [response lastsynctime] ?: [nsnull null], @"currenttimestamp": [response currenttimestamp] ?: [nsnull null], @"brokerurl": [response brokerurl] ?: [nsnull null], @"imagelink": [response imagelink] ?: [nsnull null], @"statusmessage": [response statusmessage] ?: [nsnull null], @"encryptionkey": [response encryptionkey] ?: [nsnull null], @"displayname": [response displayname] ?: [nsnull null], @"notificationsoundfilename": [response notificationsoundfilename] ?: [nsnull null] };
Comments
Post a Comment