4

I updated to Xcode 7 when it was released, but I haven't had a chance to use since the update until now. While making a game, I needed to use arc4random like this:

let RandomPosNmber = arc4random() % 4

When I tried to add it manually, it continued to give me errors. The only options were:

arc4random_addrandom(UnsafeMutablePointer<UInt8>, Int32)

arc4random_buf(UnsafeMutablePointer<Void>, Int)

arc4random_stir()

Did Apple remove arc4random forever or temporarily? What would be an alternative for the code I provided above? If more code is needed then I'll will provide it.

behind the aura
  • 296
  • 2
  • 14
  • Works as expected here, if I create a new project in Xcode and paste in that line of code. Quit and relaunch Xcode, maybe? – Tom Harrington Oct 21 '15 at 03:09
  • 4
    `arc4random()` and `arc4random_uniform()` are missing from the *auto-completion* (and I think that has been observed before). But it compiles if you type it it. – Martin R Oct 21 '15 at 04:48

1 Answers1

4

No, arc4random it is not missing. Your code runs fine here. Make sure you add import UIKit for iOS projects or import Cocoa for OSX projects. You should use arc4random_uniform.

let randomPositionNumber = arc4random_uniform(4)

Deleting Xcode preferences might help using terminal:

defaults delete com.apple.dt.Xcode 
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
  • 1
    OP's code is right. I guess why you get a downvote is because your answer doesn't really solve or explain his problem. – WangYudong Oct 21 '15 at 03:35
  • 1
    @WangYudong btw UIKit includes stdlib.h where arc4random is declared. So this might solve the issue. Also as stated by the OP he has just upgraded Xcode, so deleting the preferences might help. – Leo Dabus Oct 21 '15 at 03:40
  • If stdlib.h were not included then the other arc4random_xxx functions would also not compile. – Martin R Oct 21 '15 at 04:50
  • @MartinR thats why I added also the option for him to try reseting Xcode preferences – Leo Dabus Oct 21 '15 at 04:51