Showing events with Swift
allyrgb opened this issue · 5 comments
The Swift demo displays the month, week and day views ok, but I can't get it to show any events, i.e. it doesn't show the event dots or the event title. It appears that the event is being created ok.
The Obj-C version of the demo works fine. Any help appreciated. Thanks.
Can you please provide some screenshots and sample code?
Thanks for your reply.
To get the Swift Demo code to build with Swift 1.2, I had to change override init to convenience init and add 'title as String' in CKCalendarEvent call. I also had to use viewDidAppear to get the calendar on screen. Works ok apart from not showing the test event.
import UIKit
import MBCalendarKit
class ViewController: CKCalendarViewController, CKCalendarViewDelegate, CKCalendarViewDataSource {
let calendar = CKCalendarViewController()
var data : NSMutableDictionary = NSMutableDictionary()
convenience init() {
self.init()
self.data = NSMutableDictionary()
}
required init(coder aDecoder: NSCoder) {
data = NSMutableDictionary()
super.init(coder: aDecoder)
}
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
self.data = NSMutableDictionary()
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
self.dataSource = self
let title: NSString = NSLocalizedString("Swift Demo", comment: "")
let date: NSDate = NSDate(day: 10, month: 7, year: 2015)
let event: CKCalendarEvent = CKCalendarEvent(title: title as String, andDate: date, andInfo: nil)
self.data[date] = [event]
}
func calendarView(calendarView: CKCalendarView!, eventsForDate date: NSDate!) -> [AnyObject]! {
return self.data.objectForKey(date) as! [AnyObject]!
}
override func viewDidAppear(animated: Bool) {
self.presentViewController(calendar, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
Did you ever work this out?
Hi, No. I decided that I didn't have enough knowledge of Swift, so I put it to one side while I try to remedy that. Thanks.
Ok, thanks.