Re: NSStream's enum of NSStreamEventEndEncountered.
Re: NSStream's enum of NSStreamEventEndEncountered.
- Subject: Re: NSStream's enum of NSStreamEventEndEncountered.
- From: Alex Zavatone <email@hidden>
- Date: Thu, 24 Jul 2014 17:07:49 -0400
On Jul 24, 2014, at 4:43 PM, Quincey Morris wrote:
> On Jul 24, 2014, at 11:58 , edward taffel <email@hidden> wrote:
>
>> NSStreamEventOpenCompleted = 1 << 0,
>>
>> a point of style?
>
> Supposition:
>
> It’s point of API self-documentation. The shift indicates that this is a bit mask (or bit field) value, and hence that the enum’s members can usefully be OR’ed together. Unshifted, the members would be whole values, and therefore mutually exclusive.
>
> But I wouldn’t necessarily expect that the SDK is 100% consistent in this regard.
Just look at the two typedefs in NSStream.h file for iOS 7. It's exactly where I got screwed up.
The typedefs of NSStreamStatus and NSStreamEvent both use use NSUIntegers, but both declare them differently and one comes right after each other.
typedef NS_ENUM(NSUInteger, NSStreamStatus) {
NSStreamStatusNotOpen = 0,
NSStreamStatusOpening = 1,
NSStreamStatusOpen = 2,
NSStreamStatusReading = 3,
NSStreamStatusWriting = 4,
NSStreamStatusAtEnd = 5,
NSStreamStatusClosed = 6,
NSStreamStatusError = 7
};
typedef NS_OPTIONS(NSUInteger, NSStreamEvent) {
NSStreamEventNone = 0,
NSStreamEventOpenCompleted = 1UL << 0,
NSStreamEventHasBytesAvailable = 1UL << 1,
NSStreamEventHasSpaceAvailable = 1UL << 2,
NSStreamEventErrorOccurred = 1UL << 3,
NSStreamEventEndEncountered = 1UL << 4
};
Reading the first typedef and switching back to code, I assumed that NSStreamEventEndEncountered was a uint, not a bit mask, since I eyeballed NSStreamStatus first.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden