It seems like I have the correct code, and it compiles, runs, and builds. BUT it does not carry out certain lines of code because of the following error: "NSString may not respond to EncryptAES"
The code where the warning occurs is contained below:
- (IBAction)Encrypt {
//Change the Input String to Data
NSData *objNSData = [NSData dataWithData:[Input dataUsingEncoding: NSUTF8StringEncoding]];
//Encrypt the Data
objNSData = [Input EncryptAES:Keyword.text]; //Line with Warning
I have searched StackOverflow for problems like this and figured that to cure this error I should use some sort of code like this in my header file:
#interface NSString
-(NSString*)AESEncrypt:????
#end
Would this fix the warning? If so, then what do I put where the questions go?
If this code will not fix the problem then what do I do to get rid of this error and make the code function?
EDIT: I have also tried this using NSData, I get the same resulting warning
You're calling EncryptAES class method against "Input" which based on your comment and code above ([Input dataUsingEncoding...) appears to be an NSString.
NSString does not offer an EncryptAES method:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html
Checkout these SO posts:
AES Encryption for an NSString on the iPhone
uses: http://pastie.org/426530
iPhone - AES256 Encryption Using Built In Library
See here. Apparently EncryptAES is a "category" for NSData. I doubt that it will work on an NSString.
Related
I've been working on an app for OSX (not my own, one that I am to maintain) that needs Twitter integrations and found the STTwitter wrapper. It says it's compatible down to OSX 10.7. However, when I try to compile it, I run into several compilation issues that I've tracked I think I've tracked down to not being able to compile with Objective-C literal subscripts.
I tries using the workaround suggested across the web for adding my own interfaces, but that didn't seem to help.
The first compilation error I get is "Array subscript is not an integer" at the following chunk of code in NSError+STTwitter.m:
NSMutableDictionary *md = [NSMutableDictionary dictionary];
md[NSLocalizedDescriptionKey] = message;
if(underlyingError) md[NSUnderlyingErrorKey] = underlyingError;
if(rateLimitLimit) md[kSTTwitterRateLimitLimit] = rateLimitLimit;
if(rateLimitRemaining) md[kSTTwitterRateLimitRemaining] = rateLimitRemaining;
if(rateLimitResetDate) md[kSTTwitterRateLimitResetDate] = rateLimitResetDate;
If I comment that code out, just to see what happens (the literal substring I believe), I get more issues in STTwitterOS.m
NSString *value = [keyValue[1] stringByReplacingOccurrencesOfString:#"\"" withString:#""];
[md setObject:value forKey:keyValue[0]];
Those give "Bad receiver type NSArray" and "Sending NSArray to parameter of incompatible type 'id
Any help would be appreciated. My objective c coding isn't that great....
I'm very new to Objective-C and programming in general and I'm having some difficulty solving a strange error I'm getting in my code. I've rechecked my code line-by-line but no matter what I do I get an "Expected Identifier" error on this one line.
NSString *text = [NSString stringWithFormat:#"Your total is $%.2f", [self.cartTotal]];
I've retyped the line several times to make sure that I wasn't missing any typos, but a little red arrow is pointing to the first closing bracket.
Take [self.cartTotal] out of the brackets. They're unnecessary here.
Should be:
NSString *text = [NSString stringWithFormat:#"Your total is $%.2f", self.cartTotal];
To help understand the error (assuming you're coming from a language like Java or C++), what you've written is the equivalent to writing this in say Java:
this.cartTotal.
Notice the hanging dot at the end? That's what you've done here basically. In Java, that dot suggests you're calling a method on whatever object cartTotal is, or access a public variable on that object. I'm not sure what a Java or C++ error message would say here, but this is the equivalent scenario.
Given #GregParker's excellent comment...
You created cartTotal by way of a #property.
#property double cartTotal; // or something like this
This creates three things:
A setter
A getter
An instance variable
The setter is accessed in two ways:
[self setCartTotal:value];
Or:
self.cartTotal = value;
These both do the same thing.
The getter is likewise accessed in two ways:
[self cartTotal];
Or:
self.cartTotal;
I'm currently running Mountain Lion OS X 10.8 with Xcode 4.4 installed. I'm running the iOS 5.1 simulator. I'm using Buzztouch as a learning tool while I'm studying Objective-C and Xcode. I get the following alerts when I compile, but the build succeeds. However, I would like to know exactly what is going on and how I can remedy the situation. Thank you for any assistance you can provide. Here's the code and the alerts I'm getting:
BT_fileManager.m
Data argument not used by format string
[BT_debugger showIt:self:[NSString stringWithFormat:#"readTextFileFromBundleWithEncoding ERROR using encoding NSUTF8StringEncoding, trying NSISOLatin1StringEncoding", #""]];
Data argument not used by format string
[BT_debugger showIt:self:[NSString stringWithFormat:#"readTextFileFromCacheWithEncoding ERROR using encoding NSUTF8StringEncoding, trying NSISOLatin1StringEncoding", #""]];
BT_camera_email.m
Semantic Issue
Sending 'BT_camera_email *' to parameter of incompatible type 'id'
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
NSLog(#"is camera ok");
UIActionSheet *photoSourceSheet = [[UIActionSheet alloc] initWithTitle:#"Select Image Source"
delegate:self
Again, thanks.
Greg
I have no idea what Buzztouch might be, however.... :-)
The first warning is fairly simple. In a format string there are placeholders beginning with a '%' sign to indicate where data values should be substituted. For example, to substitute a string, one would use '%#'. In the examples you show, there are no placeholders but there are data values -- empty strings. The compiler is warning that something you indicate you want to have put into the new string created by stringWithFormat: won't be.
To be sure about the second one, I'd want to see the .h file that declares BT_camera_email but my best guess is that it doesn't adopt the UIActionSheetDelegate protocol. The description of initWithTitle:... says the second parameter should be id<UIActionSheetDelegate> and that's probably what is being complained about.
I am having a major problem with my iPhone app. My problem seems basic but I cannot find out the reason for the error. I have a NSString saveDescription that is set by user's input.
savede = civilsJobDescTb.text;
I then call in a NSLog to check the string has been set, and it is. So I have no problem there.
Later in the program I create a PDF file with several details. Everything works ok except the NSString that I have set earlier. It seem as if the string no longer exists. I get an error from it. EXC_BAD_ACCESS or something like that.
Now for the weird thing. This only happens when I have a whitespace in the text box. Eg: I enter "ok" and it will work without problem. But if I enter "Everything is ok" then I get errors.
I can't see where the problem is. Any ideas?
You didn't specify if your "savede" is an ivar (instance variable) but assuming that it is,
and if you are using ARC, set a strong property to it:
#property (nonatomic, strong) NSString * savede;
self.savede = civilsJobDescTb.text;
If you are not using ARC, then make sure to retain your "savede" string after setting it. Something like:
savede = civilsJobDescTb.text;
[savede retain];
(making sure to release it when you are truly finished with it).
You can also make a copy of the string (in case the label that it's coming from disappears, or is cleared, or somehow disappears).
[savede setString: civilsJobDescTb.text];
[savde retain];
I have the following line of code:
int insertIdx = (int)[self.itemsToDisplay indexForInsertingObject:item sortedUsingBlock:^(id a, id b) {
MWFeedItem *item1 = (MWFeedItem *) a;
MWFeedItem *item2 = (MWFeedItem *) b;
return [item1.date compare:item2.date];
}];
but XCode gives me the following warning on it:
NSMutableArray' may not respond to '-indexForInsertingObject:sortedUsingBlock:
how to get rid of this warning ? and could I know where excatly this method is defined in the SDK ?
thanks so much in advance ...
-indexForInsertingObject:sortedUsingBlock: is not part of the official, public SDK. Since it looks like you haven’t declared and implemented a category on NSMutableArray that contains that method, you could write one based on this blog post by Jayway Team. Having done that, it’s just a matter of importing the header file that declares the category.
to disable the warnings for one file add this:
#pragma GCC diagnostic ignored "-Wwarning-flag"
It should ignore all warnings. The problem is however you will not see any warnings in that file. even if they are legit.