Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

markdaraju

macrumors newbie
Original poster
Sep 20, 2012
2
0
Hi all,

I have just been asked to take ownership of iOS code of one of our company's apps.
It was quite a struggle to get the code to build on my machine (OSX 10.8, Xcode4.5 and simulator 5.1/6.0) but now most of the errors have been resolved except for this one that says "Argument type 'void' is incomplete"

The line that it's pointing at is

Code:
"
	for(int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++){
---------->>       [COLOR="Red"] [output appendFormat:@"%02x", macOut.mutableBytes[i]];[/COLOR]
    }
"

Apparently , there is something wrong with variable macOut. Following is the declaration of macOut :

Code:
"	NSMutableData *macOut = [NSMutableData  dataWithLength:CC_SHA256_DIGEST_LENGTH];

	CC_SHA256(dataIn.bytes, dataIn.length,  macOut.mutableBytes);

	NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2];
"

I can't see anything missing but again, I am not very experienced in iOS programming. Appreciate if you can provide any pointers on resolving this .

Thanks,
Mark
 

Attachments

  • Screen Shot 2012-09-20 at 6.43.06 PM.png
    Screen Shot 2012-09-20 at 6.43.06 PM.png
    55.8 KB · Views: 851
Last edited by a moderator:

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,558
6,058
Two declarations I'd like to see the code for:

1 - appendFormat:
2 - mutableBytes[]

Oh, and have you tried dereferencing mutableBytes? Maybe *macOut.mutableBytes will work better...? mutableBytes[] could just be an array of pointers pointing to the actual values, thus they'd need dereferencing to be used, right? I'm not quite sure why you'd get the error that you're getting, though...

Edit: Nevermind. mutableBytes is a standard NSMutableData ivar...

2X Edit: mutableBytes is a void*. Dereferencing it (by using ) will give you a void. So shouldn't you cast it to an int before you try printing it?
 
Last edited:

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
2X Edit: mutableBytes is a void*. Dereferencing it (by using ) will give you a void. So shouldn't you cast it to an int before you try printing it?


I'm pretty sure the goal of the posted code is to step through the bytes of the NSMutableData (note how i steps), formatting each byte as hex (%02x) as it's appended to a string (appendFormat:).

Unfortunately, the returned type is void*, not uint8_t* (see the standard C header stdint.h). Which should suggest a solution if one knows basic C. It's not even specific to iOS programming or Objective-C, just basic C skills.
 

markdaraju

macrumors newbie
Original poster
Sep 20, 2012
2
0
The confusing part is this apparently compiled fine in 10.7 + Xcode 4.3 that the previos developers had used. They are no longer available for comments hence the conundrum. In the meantime I have tried a few different approaches such as type casting and using temp variables etc. but none of that seem to be helping.


Any other ideas ? I understand that I might be making very basic mistakes here but I do intend to learn as much as I can in the process.

Thanks for your responses!
 

Attachments

  • Screen Shot 2012-09-21 at 3.54.14 PM.png
    Screen Shot 2012-09-21 at 3.54.14 PM.png
    77.2 KB · Views: 464

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
The confusing part is this apparently compiled fine in 10.7 + Xcode 4.3 that the previos developers had used.

Honestly, I find that hard to believe. When I look up that method in older reference docs, it has always returned (void*). And ever since the 'void' type was created, it's been illegal to dereference a pointer to that type. So unless there was a compiler bug that somehow allowed it, or the declared return-type somehow changed for a brief period, I see no way it could ever work as given.


In the meantime I have tried a few different approaches such as type casting and using temp variables etc. but none of that seem to be helping.
When posting code, it's better to copy and paste actual text. It's much easier to work with than pictures of text.

As given in the picture, your type-cast is completely wrong. You need to cast the pointer before it's subscripted. You also need to cast it to the correct type, an unsigned byte, otherwise you won't be converting the bytes of the data, you'll be converting the bytes-interpreted-as-ints. A suitable temp variable of the correct type would also work:
Code:
uint8_t * theBytes = [macOut mutableBytes];
for(int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++){
   [output appendFormat:@"%02x", theBytes[i]];
}
As I said before, it's basic C.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.