# \[Pitch\] \`Int.init(ObjectIdentifier)\` and \`UInt.init(ObjectIdentifier)\` should have a \`bitPattern:\` label

**URL:** <https://forums.swift.org/t/pitch-int-init-objectidentifier-and-uint-init-objectidentifier-should-have-a-bitpattern-label/3384>\
**Category:** Pitches\
**Created:** [July 13, 2016, 11:39pm UTC](https://forums.swift.org/t/pitch-int-init-objectidentifier-and-uint-init-objectidentifier-should-have-a-bitpattern-label/3384 "2016-07-13T23:39:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arnold](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/arnold/32/268_2.png) [@Arnold](https://forums.swift.org/u/Arnold)\
**Post date:** [July 13, 2016, 11:39pm UTC](https://forums.swift.org/t/pitch-int-init-objectidentifier-and-uint-init-objectidentifier-should-have-a-bitpattern-label/3384/1 "2016-07-13T23:39:23Z")

</div>

Int.init(ObjectIdentifier) and UInt.init(ObjectIdentifier) should have a 'bitPattern:’ label to make it clear at the use site that we interpret the value as a bit pattern.

In Swift we have ObjectIdentifier values which uniquely identify a class instance or metatype. They are implemented as a struct which holds the value of the reference to the instance or metatype as a raw pointer.

&nbsp;&nbsp;/// A unique identifier for a class instance or metatype.  
&nbsp;&nbsp;public struct ObjectIdentifier : Hashable, Comparable {  
&nbsp;&nbsp;&nbsp;&nbsp;internal let \_value: Builtin.RawPointer  
&nbsp;&nbsp;&nbsp;&nbsp;...  
&nbsp;&nbsp;}

We have constructors for Int and Uint that capture this value. These constructors don’t have an argument label.

&nbsp;&nbsp;extension UInt {  
&nbsp;&nbsp;&nbsp;&nbsp;/// Create a `UInt` that captures the full value of `objectID`.  
&nbsp;&nbsp;&nbsp;&nbsp;public init(\_ objectID: ObjectIdentifier) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(Builtin.ptrtoint\_Word(objectID.\_value))  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;}

&nbsp;&nbsp;extension Int {  
&nbsp;&nbsp;&nbsp;&nbsp;/// Create an `Int` that captures the full value of `objectID`.  
&nbsp;&nbsp;&nbsp;&nbsp;public init(\_ objectID: ObjectIdentifier) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(bitPattern: UInt(objectID))  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;}

This proposals suggest adding a label ‘bitPattern’ to the constructor: Int.init(bitPattern: ObjectIdentifier).

&nbsp;&nbsp;extension UInt {  
&nbsp;&nbsp;&nbsp;&nbsp;/// Create a `UInt` that captures the full value of `objectID`.  
&nbsp;&nbsp;&nbsp;&nbsp;public init(bitPattern objectID: ObjectIdentifier) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(Builtin.ptrtoint\_Word(objectID.\_value))  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;}

&nbsp;&nbsp;extension Int {  
&nbsp;&nbsp;&nbsp;&nbsp;/// Create an `Int` that captures the full value of `objectID`.  
&nbsp;&nbsp;&nbsp;&nbsp;public init(bitPattern objectID: ObjectIdentifier) {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(bitPattern: UInt(objectID))  
&nbsp;&nbsp;&nbsp;&nbsp;}  
&nbsp;&nbsp;}

Motivation

> **···**
>
> ==========
> 
> Adding a label ‘bitPattern’ to the constructors makes it clear that we interpret the pointer value as a bit pattern at the use site. It is similar to what we do in other APIs, for example in "UInt(bitPattern: UnsafePointer\<Void\>(value)))"
> 
> # Impact on existing code
> 
> Existing code will have to add the bitPattern label.
> 
> # Alternatives
> 
> Leave as is.

---

<div class="post-metadata">

**Author:** ![Arnold](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/arnold/32/268_2.png) [@Arnold](https://forums.swift.org/u/Arnold)\
**Post date:** [July 15, 2016, 1:54pm UTC](https://forums.swift.org/t/pitch-int-init-objectidentifier-and-uint-init-objectidentifier-should-have-a-bitpattern-label/3384/2 "2016-07-15T13:54:46Z")

</div>

This is probably uncontroversial.

PR: ['(U)Int.init(ObjectIdentifier)' should have a 'bitPattern:' label by aschwaighofer · Pull Request #434 · apple/swift-evolution · GitHub](https://github.com/apple/swift-evolution/pull/434)

> **···**
>
> > On Jul 13, 2016, at 4:39 PM, Arnold Schwaighofer via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > Int.init(ObjectIdentifier) and UInt.init(ObjectIdentifier) should have a 'bitPattern:’ label to make it clear at the use site that we interpret the value as a bit pattern.
> > 
> > In Swift we have ObjectIdentifier values which uniquely identify a class instance or metatype. They are implemented as a struct which holds the value of the reference to the instance or metatype as a raw pointer.
> > 
> > /// A unique identifier for a class instance or metatype.  
> > public struct ObjectIdentifier : Hashable, Comparable {  
> > &nbsp;&nbsp;&nbsp;internal let \_value: Builtin.RawPointer  
> > &nbsp;&nbsp;&nbsp;...  
> > }
> > 
> > We have constructors for Int and Uint that capture this value. These constructors don’t have an argument label.
> > 
> > extension UInt {  
> > &nbsp;&nbsp;&nbsp;/// Create a `UInt` that captures the full value of `objectID`.  
> > &nbsp;&nbsp;&nbsp;public init(\_ objectID: ObjectIdentifier) {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(Builtin.ptrtoint\_Word(objectID.\_value))  
> > &nbsp;&nbsp;&nbsp;}  
> > }
> > 
> > extension Int {  
> > &nbsp;&nbsp;&nbsp;/// Create an `Int` that captures the full value of `objectID`.  
> > &nbsp;&nbsp;&nbsp;public init(\_ objectID: ObjectIdentifier) {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(bitPattern: UInt(objectID))  
> > &nbsp;&nbsp;&nbsp;}  
> > }
> > 
> > This proposals suggest adding a label ‘bitPattern’ to the constructor: Int.init(bitPattern: ObjectIdentifier).
> > 
> > extension UInt {  
> > &nbsp;&nbsp;&nbsp;/// Create a `UInt` that captures the full value of `objectID`.  
> > &nbsp;&nbsp;&nbsp;public init(bitPattern objectID: ObjectIdentifier) {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(Builtin.ptrtoint\_Word(objectID.\_value))  
> > &nbsp;&nbsp;&nbsp;}  
> > }
> > 
> > extension Int {  
> > &nbsp;&nbsp;&nbsp;/// Create an `Int` that captures the full value of `objectID`.  
> > &nbsp;&nbsp;&nbsp;public init(bitPattern objectID: ObjectIdentifier) {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(bitPattern: UInt(objectID))  
> > &nbsp;&nbsp;&nbsp;}  
> > }
> > 
> > # Motivation
> > 
> > Adding a label ‘bitPattern’ to the constructors makes it clear that we interpret the pointer value as a bit pattern at the use site. It is similar to what we do in other APIs, for example in "UInt(bitPattern: UnsafePointer\<Void\>(value)))"
> > 
> > # Impact on existing code
> > 
> > Existing code will have to add the bitPattern label.
> > 
> > # Alternatives
> > 
> > Leave as is.  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![gribozavr](https://avatars.discourse-cdn.com/v4/letter/g/65b543/32.png) [@gribozavr](https://forums.swift.org/u/gribozavr)\
**Post date:** [July 15, 2016, 4:36pm UTC](https://forums.swift.org/t/pitch-int-init-objectidentifier-and-uint-init-objectidentifier-should-have-a-bitpattern-label/3384/3 "2016-07-15T16:36:51Z")

</div>

+1!

Dmitri

> **···**
>
> On Wed, Jul 13, 2016 at 4:39 PM, Arnold Schwaighofer via swift-evolution \<swift-evolution@swift.org\> wrote:
> 
> > Int.init(ObjectIdentifier) and UInt.init(ObjectIdentifier) should have a 'bitPattern:’ label to make it clear at the use site that we interpret the value as a bit pattern.
> 
> --  
> main(i,j){for(i=2;;i++){for(j=2;j\<i;j++){if(!(i%j)){j=0;break;}}if  
> (j){printf("%d\n",i);}}} /\*Dmitri Gribenko \<gribozavr@gmail.com\>\*/

---

<div class="post-metadata">

**Author:** ![David\_Sweeris](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/david_sweeris/32/31302_2.png) [@David\_Sweeris](https://forums.swift.org/u/David_Sweeris)\
**Post date:** [July 15, 2016, 7:32pm UTC](https://forums.swift.org/t/pitch-int-init-objectidentifier-and-uint-init-objectidentifier-should-have-a-bitpattern-label/3384/4 "2016-07-15T19:32:53Z")

</div>

+1

> **···**
>
> Sent from my iPhone
> 
> > On Jul 13, 2016, at 18:39, Arnold Schwaighofer via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > Int.init(ObjectIdentifier) and UInt.init(ObjectIdentifier) should have a 'bitPattern:’ label to make it clear at the use site that we interpret the value as a bit pattern.
> > 
> > In Swift we have ObjectIdentifier values which uniquely identify a class instance or metatype. They are implemented as a struct which holds the value of the reference to the instance or metatype as a raw pointer.
> > 
> > /// A unique identifier for a class instance or metatype.  
> > public struct ObjectIdentifier : Hashable, Comparable {  
> > &nbsp;&nbsp;&nbsp;internal let \_value: Builtin.RawPointer  
> > &nbsp;&nbsp;&nbsp;...  
> > }
> > 
> > We have constructors for Int and Uint that capture this value. These constructors don’t have an argument label.
> > 
> > extension UInt {  
> > &nbsp;&nbsp;&nbsp;/// Create a `UInt` that captures the full value of `objectID`.  
> > &nbsp;&nbsp;&nbsp;public init(\_ objectID: ObjectIdentifier) {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(Builtin.ptrtoint\_Word(objectID.\_value))  
> > &nbsp;&nbsp;&nbsp;}  
> > }
> > 
> > extension Int {  
> > &nbsp;&nbsp;&nbsp;/// Create an `Int` that captures the full value of `objectID`.  
> > &nbsp;&nbsp;&nbsp;public init(\_ objectID: ObjectIdentifier) {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(bitPattern: UInt(objectID))  
> > &nbsp;&nbsp;&nbsp;}  
> > }
> > 
> > This proposals suggest adding a label ‘bitPattern’ to the constructor: Int.init(bitPattern: ObjectIdentifier).
> > 
> > extension UInt {  
> > &nbsp;&nbsp;&nbsp;/// Create a `UInt` that captures the full value of `objectID`.  
> > &nbsp;&nbsp;&nbsp;public init(bitPattern objectID: ObjectIdentifier) {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(Builtin.ptrtoint\_Word(objectID.\_value))  
> > &nbsp;&nbsp;&nbsp;}  
> > }
> > 
> > extension Int {  
> > &nbsp;&nbsp;&nbsp;/// Create an `Int` that captures the full value of `objectID`.  
> > &nbsp;&nbsp;&nbsp;public init(bitPattern objectID: ObjectIdentifier) {  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(bitPattern: UInt(objectID))  
> > &nbsp;&nbsp;&nbsp;}  
> > }
> > 
> > # Motivation
> > 
> > Adding a label ‘bitPattern’ to the constructors makes it clear that we interpret the pointer value as a bit pattern at the use site. It is similar to what we do in other APIs, for example in "UInt(bitPattern: UnsafePointer\<Void\>(value)))"
> > 
> > # Impact on existing code
> > 
> > Existing code will have to add the bitPattern label.
> > 
> > # Alternatives
> > 
> > Leave as is.  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)

---

<div class="post-metadata">

**Author:** ![dabrahams](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dabrahams/32/9815_2.png) [@dabrahams](https://forums.swift.org/u/dabrahams)\
**Post date:** [July 15, 2016, 9:58pm UTC](https://forums.swift.org/t/pitch-int-init-objectidentifier-and-uint-init-objectidentifier-should-have-a-bitpattern-label/3384/5 "2016-07-15T21:58:21Z")

</div>

> This is probably uncontroversial.
> 
> PR: ['(U)Int.init(ObjectIdentifier)' should have a 'bitPattern:' label by aschwaighofer · Pull Request #434 · apple/swift-evolution · GitHub](https://github.com/apple/swift-evolution/pull/434)

+1

> **···**
>
> on Fri Jul 15 2016, Arnold Schwaighofer \<swift-evolution@swift.org\> wrote:
> 
> > > On Jul 13, 2016, at 4:39 PM, Arnold Schwaighofer via swift-evolution \<swift-evolution@swift.org\> wrote:
> > > 
> > > Int.init(ObjectIdentifier) and UInt.init(ObjectIdentifier) should have a 'bitPattern:’ label to make it clear at the use site that we interpret the value as a bit pattern.
> > > 
> > > In Swift we have ObjectIdentifier values which uniquely identify a class instance or metatype. They are implemented as a struct which holds the value of the reference to the instance or metatype as a raw pointer.
> > > 
> > > /// A unique identifier for a class instance or metatype.  
> > > public struct ObjectIdentifier : Hashable, Comparable {  
> > > &nbsp;&nbsp;&nbsp;internal let \_value: Builtin.RawPointer  
> > > &nbsp;&nbsp;&nbsp;...  
> > > }
> > > 
> > > We have constructors for Int and Uint that capture this value. These constructors don’t have an argument label.
> > > 
> > > extension UInt {  
> > > &nbsp;&nbsp;&nbsp;/// Create a `UInt` that captures the full value of `objectID`.  
> > > &nbsp;&nbsp;&nbsp;public init(\_ objectID: ObjectIdentifier) {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(Builtin.ptrtoint\_Word(objectID.\_value))  
> > > &nbsp;&nbsp;&nbsp;}  
> > > }
> > > 
> > > extension Int {  
> > > &nbsp;&nbsp;&nbsp;/// Create an `Int` that captures the full value of `objectID`.  
> > > &nbsp;&nbsp;&nbsp;public init(\_ objectID: ObjectIdentifier) {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(bitPattern: UInt(objectID))  
> > > &nbsp;&nbsp;&nbsp;}  
> > > }
> > > 
> > > This proposals suggest adding a label ‘bitPattern’ to the constructor: Int.init(bitPattern: ObjectIdentifier).
> > > 
> > > extension UInt {  
> > > &nbsp;&nbsp;&nbsp;/// Create a `UInt` that captures the full value of `objectID`.  
> > > &nbsp;&nbsp;&nbsp;public init(bitPattern objectID: ObjectIdentifier) {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(Builtin.ptrtoint\_Word(objectID.\_value))  
> > > &nbsp;&nbsp;&nbsp;}  
> > > }
> > > 
> > > extension Int {  
> > > &nbsp;&nbsp;&nbsp;/// Create an `Int` that captures the full value of `objectID`.  
> > > &nbsp;&nbsp;&nbsp;public init(bitPattern objectID: ObjectIdentifier) {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.init(bitPattern: UInt(objectID))  
> > > &nbsp;&nbsp;&nbsp;}  
> > > }
> > > 
> > > # Motivation
> > > 
> > > Adding a label ‘bitPattern’ to the constructors makes it clear that we interpret the pointer value as a bit pattern at the use site. It is similar to what we do in other APIs, for example in "UInt(bitPattern: UnsafePointer\<Void\>(value)))"
> > > 
> > > # Impact on existing code
> > > 
> > > Existing code will have to add the bitPattern label.
> > > 
> > > # Alternatives
> > > 
> > > Leave as is.  
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > swift-evolution mailing list  
> > > swift-evolution@swift.org  
> > > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
> 
> --  
> Dave

---

<div class="post-metadata">

**Author:** ![Charlie\_Monroe1](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@Charlie\_Monroe1](https://forums.swift.org/u/Charlie_Monroe1)\
**Post date:** [July 15, 2016, 2:05pm UTC](https://forums.swift.org/t/pitch-int-init-objectidentifier-and-uint-init-objectidentifier-should-have-a-bitpattern-label/3384/6 "2016-07-15T14:05:23Z")

</div>

+1. Agreed. Otherwise, it's kind of a cryptic initializer.

> **···**
>
> > On Jul 15, 2016, at 3:54 PM, Arnold Schwaighofer via swift-evolution \<swift-evolution@swift.org\> wrote:
> > 
> > This is probably uncontroversial.
> > 
> > PR: ['(U)Int.init(ObjectIdentifier)' should have a 'bitPattern:' label by aschwaighofer · Pull Request #434 · apple/swift-evolution · GitHub](https://github.com/apple/swift-evolution/pull/434)
> > 
> > > On Jul 13, 2016, at 4:39 PM, Arnold Schwaighofer via swift-evolution \<swift-evolution@swift.org\> wrote:
> > > 
> > > Int.init(ObjectIdentifier) and UInt.init(ObjectIdentifier) should have a 'bitPattern:’ label to make it clear at the use site that we interpret the value as a bit pattern.
> > > 
> > > In Swift we have ObjectIdentifier values which uniquely identify a class instance or metatype. They are implemented as a struct which holds the value of the reference to the instance or metatype as a raw pointer.
> > > 
> > > /// A unique identifier for a class instance or metatype.  
> > > public struct ObjectIdentifier : Hashable, Comparable {  
> > > &nbsp;&nbsp;internal let \_value: Builtin.RawPointer  
> > > &nbsp;&nbsp;...  
> > > }
> > > 
> > > We have constructors for Int and Uint that capture this value. These constructors don’t have an argument label.
> > > 
> > > extension UInt {  
> > > &nbsp;&nbsp;/// Create a `UInt` that captures the full value of `objectID`.  
> > > &nbsp;&nbsp;public init(\_ objectID: ObjectIdentifier) {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;self.init(Builtin.ptrtoint\_Word(objectID.\_value))  
> > > &nbsp;&nbsp;}  
> > > }
> > > 
> > > extension Int {  
> > > &nbsp;&nbsp;/// Create an `Int` that captures the full value of `objectID`.  
> > > &nbsp;&nbsp;public init(\_ objectID: ObjectIdentifier) {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;self.init(bitPattern: UInt(objectID))  
> > > &nbsp;&nbsp;}  
> > > }
> > > 
> > > This proposals suggest adding a label ‘bitPattern’ to the constructor: Int.init(bitPattern: ObjectIdentifier).
> > > 
> > > extension UInt {  
> > > &nbsp;&nbsp;/// Create a `UInt` that captures the full value of `objectID`.  
> > > &nbsp;&nbsp;public init(bitPattern objectID: ObjectIdentifier) {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;self.init(Builtin.ptrtoint\_Word(objectID.\_value))  
> > > &nbsp;&nbsp;}  
> > > }
> > > 
> > > extension Int {  
> > > &nbsp;&nbsp;/// Create an `Int` that captures the full value of `objectID`.  
> > > &nbsp;&nbsp;public init(bitPattern objectID: ObjectIdentifier) {  
> > > &nbsp;&nbsp;&nbsp;&nbsp;self.init(bitPattern: UInt(objectID))  
> > > &nbsp;&nbsp;}  
> > > }
> > > 
> > > # Motivation
> > > 
> > > Adding a label ‘bitPattern’ to the constructors makes it clear that we interpret the pointer value as a bit pattern at the use site. It is similar to what we do in other APIs, for example in "UInt(bitPattern: UnsafePointer\<Void\>(value)))"
> > > 
> > > # Impact on existing code
> > > 
> > > Existing code will have to add the bitPattern label.
> > > 
> > > # Alternatives
> > > 
> > > Leave as is.  
> > > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > > swift-evolution mailing list  
> > > swift-evolution@swift.org  
> > > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
> > 
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > swift-evolution mailing list  
> > swift-evolution@swift.org  
> > [https://lists.swift.org/mailman/listinfo/swift-evolution](https://lists.swift.org/mailman/listinfo/swift-evolution)
