• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Shifting in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Shifting in Swift


  • Subject: Shifting in Swift
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Wed, 02 Jul 2014 20:10:07 +0700

I am trying to convert an Objective-C class to Swift (just as a learning exercise):

#define CHUNK_TYPE	uint32_t	//	OSAtomicOr32 needs uint32_t
#define	CHUNK_SIZE_IN_BYTES		( sizeof(CHUNK_TYPE) )
#define	CHUNK_SIZE_IN_BITS		( CHUNK_SIZE_IN_BYTES * 8 )

for( NSUInteger bix = 0; bix < CHUNK_SIZE_IN_BITS; bix++ )
{
	CHUNK_TYPE a = (CHUNK_TYPE)0x1 << bix;
}


In Swift this becomes:

typealias CHUNK_TYPE = UInt32
let	CHUNK_SIZE_IN_BYTES : Int = sizeof(CHUNK_TYPE)
let	CHUNK_SIZE_IN_BITS = CHUNK_SIZE_IN_BYTES * 8

let one : CHUNK_TYPE = 0x1
let thirtyTwo : UInt32 = CHUNK_SIZE_IN_BITS // Error: NSNumber is not a subtype of UInt32

for var bix : UInt32 = 0; bix < thirtyTwo; bix++
{
	let a = one << bix
}

But it does not work: I cannot convert an Int into UInt32.

Should be possible, but I cannot find the (probably simple and obvious) solution.

Gerriet.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Shifting in Swift
      • From: Roland King <email@hidden>
  • Prev by Date: Re: enumerate arrays in Swift
  • Next by Date: Re: Shifting in Swift
  • Previous by thread: Re: enumerate arrays in Swift
  • Next by thread: Re: Shifting in Swift
  • Index(es):
    • Date
    • Thread