Suchita Darvekar
Suchita Darvekar

Reputation: 11

Warning: string is not a string literal(potentially insecure) for code

I am a beginner in iOS, can some one help me:
I am getting warning: string is not a string literal (potentially insecure) for below code

-( void )gettingEntitySchemaForGivenKayValueFromDataBase:( RequestType )requestType ParamDict:( NSDictionary * )parameterDict
    {
        PersistenceFromDataBase *persistanceDataObj=[ PersistenceFromDataBase sharedInstance ];
        //[ NSJSONSerialization dataWithJSONObject:[ persistanceDataObj getEntitySchemaForGinvenEntityIs:parameterDict ] options:NSJSONWritingPrettyPrinted error:nil ];
        NSDictionary  *dataDict= [ persistanceDataObj getEntitySchemaForGinvenEntityIs:parameterDict ];
        id datatoserialize=[ dataDict objectForKey:VIEWS_KEY ];
        NSLog([ NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil ])
    ;
        NSLog(@" entitySchemaForEntityId:%@",dataDict );
       // [[ NSNotificationQueue defaultQueue ]  enqueueNotification:[ NSNotification notificationWithName:ENTITYSCHEMANOTIFICATION object:nil userInfo:@{ USER_INFO:dataDict }] postingStyle:NSPostWhenIdle ];
        // sent view data to view controller



    }

Upvotes: 1

Views: 199

Answers (3)

Vyachaslav Gerchicov
Vyachaslav Gerchicov

Reputation: 2457

Replace your

NSLog([ NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil ])
    ;

with the following one

NSLog(@"%@", [NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil]);

Upvotes: 0

Ganesh Somani
Ganesh Somani

Reputation: 2360

For your code NSLog([ NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil ]), NSLog actually prints a string and needs a string format as input.

The function dataWithJSONObject:options:error: returns NSData and Not NSString, hence the warning.

You may try this instead NSLog(@"%@",[ NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil]);

Upvotes: 0

Schemetrical
Schemetrical

Reputation: 5536

Your NSLog is missing a format specifier. Use this instead:

NSLog(@"%@",[NSJSONSerialization dataWithJSONObject:datatoserialize options:NSJSONWritingPrettyPrinted error:nil]) ;

Upvotes: 1

Related Questions