• 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
Re: C-Arrays in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C-Arrays in Swift


  • Subject: Re: C-Arrays in Swift
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Fri, 04 Jul 2014 13:46:51 +0700

On 4 Jul 2014, at 07:19, Roland King <email@hidden> wrote:

> I was going to say read this
>
> https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html

Good advice. But this seems to be just the chapter “Interacting with C APIs” in the book: “Using Swift with Cocoa and Objective-C.”  which I have read repeatedly.

As you said: this is somewhat short on usable examples.


>
> On 3 Jul, 2014, at 11:50 pm, Gerriet M. Denkmann <email@hidden> wrote:
>
>> In Objective-C I have:
>>
>> NSUInteger nbrOfInts = someObject.nbrOfUnsignedInts;
>> const NSUInteger *someInts = someObject.arrayOfUnsignedInts;
>>
>> for( NSUInteger intIndex = 0; intIndex < nbrOfInts; intIndex ++ )
>> {
>> 	NSUInteger anInt = someInts[intIndex] ;
>> }


Converted to Swift this now is:

let nbrOfInts = someObject.nbrOfUnsignedInts
let someIntPointer : CConstPointer<Int> = someObject.arrayOfUnsignedInts
let someInts = UnsafePointer<Int>(someIntPointer)

for index in 0..nbrOfInts
{
	println( "int[\(index)] = \(someInts[index])" )
}

and it seems to be working.

One strange point though:
My int array contains NSUIntegers, but:
	let someIntPointer : CConstPointer<UInt> = someObject.arrayOfUnsignedInts
does not work.

Thanks a lot for your most valuable help!


Kind regards

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


References: 
 >C-Arrays in Swift (From: "Gerriet M. Denkmann" <email@hidden>)
 >Re: C-Arrays in Swift (From: Roland King <email@hidden>)

  • Prev by Date: Re: C-Arrays in Swift
  • Next by Date: NSByteCountFormatter in Swift
  • Previous by thread: Re: C-Arrays in Swift
  • Next by thread: Sudden provisioning profile issues
  • Index(es):
    • Date
    • Thread