Skip to content

Instantly share code, notes, and snippets.

@toshi0383
Created November 24, 2016 01:12
Show Gist options
  • Save toshi0383/15ee1b3eb03e57e99ec96cc08fbd2b9d to your computer and use it in GitHub Desktop.
Save toshi0383/15ee1b3eb03e57e99ec96cc08fbd2b9d to your computer and use it in GitHub Desktop.
SwiftのArrayは暗黙的にcountの型で長さが制限される。countはIntなので、64bitのMacBookProだとINT64_MAXが限界になる。ということを知った。 #CodePiece
import Foundation
let a = (0..<UINT32_MAX).lazy.map{$0}
print(a.count) // 4294967295
let b = (0..<INT64_MAX).lazy.map{$0}
print(b.count) // 9223372036854775807
let bb = (0...INT64_MAX).lazy.map{$0}
print(bb.count) // <= EXC_BAD_INSTRUCTION
let c = (0..<UINT64_MAX).lazy.map{$0}
print(c.count) // <= EXC_BAD_INSTRUCTION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment