简体   繁体   English

为什么会看到错误“格式不是字符串文字且没有格式参数”?

[英]Why am I seeing the error “Format is not a string literal and no format arguments”?

i am creating a music application in iphone where i am integrating twitter in my iphone so that a user can listen to a particular song click on the twitter tab ,log in to twitter and post his comment in to twitter.and i need that his username and password should be saved when he click on save username and password button so that he remain logged in when he is in the application. 我正在iphone中创建音乐应用程序,在其中将twitter集成到iphone中,以便用户可以收听特定歌曲,单击twitter选项卡,登录到twitter并将其评论发布到twitter.and我需要他的用户名当他单击“保存用户名和密码”按钮时,应该保存密码和密码,以便他在应用程序中时保持登录状态。

I have done the code of saving username and password but i get an error indicating that ""FORMAT IS NOT A STRING LITERAL AND NO FORMAT ARGUMENTS"" 我已经完成了保存用户名和密码的代码,但是收到一条错误消息,指出““ FORMAT不是字符串文字,没有格式参数””

Here is my code: 这是我的代码:

-(IBAction)SaveAll:(id)sender{


    UsernameString =[[NSString alloc]initWithFormat:text1.text]; "FORMAT IS NOT A STRING LITERAL AND NO FORMAT ARGUMENTS"

    [text1 setText:UsernameString];
    NSUserDefaults *UsernameDefault =[NSUserDefaults standardUserDefaults];
    [UsernameDefault setObject:UsernameString forKey:@"Stringkey"];



    PasswordString =[[NSString alloc]initWithFormat:text2.text]; "FORMAT IS NOT A STRING LITERAL AND NO FORMAT ARGUMENTS"

    [text2 setText:PasswordString];
    NSUserDefaults *PasswordDefault =[NSUserDefaults standardUserDefaults];
    [PasswordDefault setObject:PasswordString forKey:@"Stringkey2"];

}

Please help me in solving this problem so that when i click on the username and password button my username and password should be saved. 请帮助我解决此问题,以便当我单击用户名和密码按钮时,应保存我的用户名和密码。

Use InitWithFormat if you want to create a String that is composed by several components, like a string and an integer for example then you would do something like this 如果要创建由多个组件组成的字符串(例如,例如字符串和整数),请使用InitWithFormat,然后执行以下操作

NSString *myString = [NSString stringWithFormat:@"%@ costs %i"itemName, itemprice];

itemName would be an NSString Object, itemprice would be an integer. itemName将是一个NSString对象,itemprice将是一个整数。

in your case, try doing it the following way: 根据您的情况,请尝试通过以下方式进行操作:

UsernameString =[[NSString alloc]initWithString:text1.text];

or even easier 甚至更容易

UsernameString = text1.text;

note: I would NOT recommend to store Passwords or any other sensitive information into userdefaults a better (more safe/secure way) to store passwords is to use the devices keychain, where stored information is heavily encrypted and access happens in a safe way. 注意:我不建议将密码或任何其他敏感信息存储到用户默认值中,更好的(更安全/更安全的方式)存储密码是使用设备钥匙串,其中存储的信息被高度加密并且访问以安全的方式进行。

also it's easy to use: 也很容易使用:

Simple iPhone Tutorial: Password Management using the keychain by using SFHFKeychainUtils 简单的iPhone教程:使用SFHFKeychainUtils使用钥匙串进行密码管理

Hope that helps. 希望能有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:格式不是字符串文字,也没有格式 arguments - warning: format not a string literal and no format arguments 警告:格式不是字符串文字,也没有格式参数 - warning: format not a string literal and no format arguments NSLocalizedString - 格式不是字符串文字而没有格式参数(xcode) - NSLocalizedString - Format not a string literal and no format arguments (xcode) 格式不是字符串文字,没有格式参数(不涉及NSLog) - format not a string literal and no format arguments (not involving NSLog) 警告消息“格式不是字符串文字,没有格式参数” - warning message “format not a string literal and no format arguments” 关于字符串警告格式不是字符串文字,也没有格式参数 - About String warning format is not a string literal and no format arguments DebugLog Format字符串不是字符串文字 - DebugLog Format string is not a string literal 新的ios4格式不是字符串文字 - New ios4 Format not a string literal 为什么会看到以下警告:“假定没有匹配方法签名的消息将返回'id'并接受'...'作为参数”? - Why am I seeing the following warning: “Messages without a matching method signature wii be assumed to return 'id' and accept'…'as arguments ”? 将表示我的格式说明符的字符串传递给stringWithFormat并查看问题 - Passing a string representing my format specifier into stringWithFormat and seeing issues
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM