r/iOSProgramming • • Oct 11 '18

Aren’t we all glad

Post image
211 Upvotes

19 comments sorted by

3

u/[deleted] Oct 12 '18

What does arc4 mean?

2

u/DooberSnoober_1 Oct 12 '18

Arc4random used to be the way you would generate a random integer in swift.

2

u/[deleted] Oct 12 '18

I know that; I was asking what Arc4 means. Like why is it called Arc4random.

3

u/mujjingun Oct 17 '18

RC4 "Rivest Cipher 4" has been designed by RSA Data Security, Inc. It was posted anonymously to the USENET and was confirmed to be equivalent by several sources who had access to the original cipher. Since RC4 used to be a trade secret, the cipher is now referred to as ARC4 "Alleged RC4".

1

u/DanielPhermous Oct 12 '18

It's not even Swift. It's a UNIX thing if I remember. Probably Linux too.

7

u/dmitriy_shmilo Oct 12 '18

It's called C standard library.

5

u/accatyyc Oct 12 '18

just to nitpick a bit, arc4random is not part of the C standard library - it's part of libbsd. With libc you have to get by with rand()

1

u/dmitriy_shmilo Oct 12 '18

Muh bad, sorry.

16

u/xylont Oct 11 '18

Did this happen?

39

u/[deleted] Oct 11 '18

not exactly like this but Swift 4.2 has a heap of random functions, e.g.

Int.random(in: 0..<10)

18

u/xyrer Oct 11 '18

Nice! Much cleaner

5

u/Sdmf195 Oct 11 '18

Hehe :)

5

u/quellish Oct 11 '18

Depending on what you’re using them for the GameKit methods can be vastly superior.

11

u/lolcoderer Oct 11 '18

Now if that could only solve the stupid Double vs CGFloat crap.

I want to do this

var width = aDate.timeIntervalSince(anotherDate) * pixPerSec
let view = UIView(frame: CGRect(x:0, y:0, width: width, height: self.frame.height)

Instead of this stupid crap:

var width = aDate.timeIntervalSince(anotherDate) * pixPerSec
let view = UIView(frame: CGRect(x:0, y:0, width: CGFloat(width), height: self.frame.height)

6

u/ducusheKlihE Oct 11 '18

Just extend CGRect with a custom convenience initializer.

12

u/lolcoderer Oct 11 '18 edited Oct 11 '18

That isn't the problem and that would not help... There are already tons of CGRect initializers. There is a CGRect for CGFloat params and CGRect for Double params - the issue is that there are many places in my code (and I imagine this is widely observed by others as well) - I was just using TimeInterval here as an example where this could come up - where both Doubles and CGFloats are used whose values end up being assigned to Core Graphics properties.

Having to manually coerce a Double to CGFloat just to use it in place of a CGFloat is just silly - they are the same exact thing internally (on 64 bit systems) I believe.

My code is literally littered with casts of Doubles to CGFloats - and it feels so unnecessary.

2

u/DanielPhermous Oct 11 '18

Yeeess.... But I kind of needed to seed, so my appreciation was short lived. However, I did find a use for array.shuffle().

0

u/gistya Oct 12 '18

Dude has such small hands.