Skip to content

Commit

Permalink
Merge pull request #350 from MojtabaHs/master
Browse files Browse the repository at this point in the history
Refactor: `arc4random` to `randomElement` because `arc4random` is a deprecated method in swift
  • Loading branch information
richardtop authored Oct 11, 2022
2 parents 3125c7a + 4f57f0c commit fd0eadb
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ class CustomCalendarExampleController: DayViewController {
let duration = Int.random(in: 60 ... 160)
event.dateInterval = DateInterval(start: workingDate, duration: TimeInterval(duration * 60))

var info = data[Int(arc4random_uniform(UInt32(data.count)))]
var info = data.randomElement() ?? []

let timezone = dayView.calendar.timeZone
print(timezone)

info.append(dateIntervalFormatter.string(from: event.dateInterval.start, to: event.dateInterval.end))
event.text = info.reduce("", {$0 + $1 + "\n"})
event.color = colors[Int(arc4random_uniform(UInt32(colors.count)))]
event.isAllDay = Int(arc4random_uniform(2)) % 2 == 0
event.color = colors.randomElement() ?? .red
event.isAllDay = Bool.random()
event.lineBreakMode = .byTruncatingTail

events.append(event)
Expand Down Expand Up @@ -160,13 +160,13 @@ class CustomCalendarExampleController: DayViewController {
}

private func generateEventNearDate(_ date: Date) -> EventDescriptor {
let duration = Int(arc4random_uniform(160) + 60)
let duration = (60...220).randomElement()!
let startDate = Calendar.current.date(byAdding: .minute, value: -Int(CGFloat(duration) / 2), to: date)!
let event = Event()

event.dateInterval = DateInterval(start: startDate, duration: TimeInterval(duration * 60))

var info = data[Int(arc4random_uniform(UInt32(data.count)))]
var info = data.randomElement()!

info.append(dateIntervalFormatter.string(from: event.dateInterval)!)
event.text = info.reduce("", {$0 + $1 + "\n"})
Expand Down

0 comments on commit fd0eadb

Please sign in to comment.