Note that there are some explanatory texts on larger screens.

plurals
  1. POBonjour Networking Help on iPhone WiTap sample
    primarykey
    data
    text
    <p>I can follow most of Apple's WiTap sample, but am sort of stumped on this bit in the send method:</p> <pre><code>- (void) send:(const uint8_t)message { if (_outStream &amp;&amp; [_outStream hasSpaceAvailable]) if([_outStream write:(const uint8_t *)&amp;message maxLength:sizeof(const uint8_t)] == -1) [self _showAlert:@"Failed sending data to peer"]; } - (void) activateView:(TapView*)view { NSLog(@"ACTIVATE TAG: %d", [view tag]); //[self send:[view tag] | 0x80]; [self send:[view tag]]; } - (void) deactivateView:(TapView*)view { NSLog(@"DEACTIVATE TAG: %d", [view tag]); //[self send:[view tag] &amp; 0x7f]; [self send:[view tag]]; } </code></pre> <p>Note that I have changed the send: argument to just the tag of the views, which are numbered 1-9. Originally the code had the bitwise AND and OR adjustments.</p> <p>WHY?</p> <p>I get the fact that the send method needs a <code>uint8_t</code>, but is that why the bitwise stuff is there? To turn a NSInteger into a unint8_t?</p> <p>The code doesn't work with my changes above. It will log fine and visually the client will function correctly, but the messages aren't being sent/received correctly from client to client.</p> <p>Can someone explain in small words what the bitwise stuff is doing? Or am I correct?</p> <p>Thanks! This is my first question to SO so please be kind. </p> <hr> <p>thanks for the response. I am still puzzled a bit. Get it?</p> <p>Basically, why?</p> <p>Is this just a geeky way of passing an identifier? Each of those views have a tag #, why not just pass that, and toggle the state (up/down) from the view class?</p> <p>Is this just a case of "this is how the person who wrote it did it", or am I missing a crucial piece of the puzzle in that this is how I should also be structuring my code.</p> <p>I would just want to pass a tag # and then have that tag decide what to do in a clearly readable function like <code>toggleUpOrDownState</code> or something.</p> <p>This bitwise stuff always makes me feel stupid I guess, unless it is necessary, etc. Then I feel stupid but manage to muddle through somehow anyway. : )</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload