Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App with Swift Structs As Data Models Finishing Up Our Model

Patrick McLeod
Patrick McLeod
5,913 Points

Is there a reason why we cant use arc4random_uniform()

Hi Unless Pasan is purposefully trying to make us use the GameKit Framework, is there a reason why we cant use Int(arc4random_uniform(UInt32(facts.count)))? Many thanks in advanced. Cheers

2 Answers

Emin Grbo
Emin Grbo
13,092 Points

It is an Objective C way of doing things and "messy" since you need to do several conversions. I like arc4random and used it before, but things are moving fast an i think Pasan wants to make people realize that there are some new ways of doing things that might save some time.

Hope this helped, don't forget to mark the answer if it did :)

For anyone curious: yes, you can use arc4random_uniform() for this; although — as Emin already stated — the code's just not as clean, and I believe the GameKit random generator is generally the preferred method of the two at this point.

I just added code using this approach on a post asking a similar question if anyone's still looking to see how this might work.