learn watchos programming!
TRANSCRIPT
![Page 1: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/1.jpg)
Learn watchOS
Programming!
![Page 2: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/2.jpg)
Communication ChannelGoogle Document for live chat - http://tiny.cc/watchOSTechTalk
Github link for the project - https://github.com/patilsnehal/watchOSTableview
![Page 3: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/3.jpg)
Create watchOS Application with tableview
![Page 4: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/4.jpg)
Create Project
![Page 5: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/5.jpg)
Add tableview
![Page 6: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/6.jpg)
Change the color of the global tint
![Page 7: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/7.jpg)
Change Identifier
![Page 8: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/8.jpg)
Add Group and then labels to it
![Page 9: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/9.jpg)
Change font, alignment etc
![Page 10: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/10.jpg)
Add a watchKit class
![Page 11: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/11.jpg)
ScheduleInterfaceController
![Page 12: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/12.jpg)
Change the class type as ScheduleInterfaceController
![Page 13: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/13.jpg)
Lets do some coding finally :)
Connect table @IBOutlet var WWCMeetupTable: WKInterfaceTable!
Set up Number of rows WWCMeetupTable.setNumberOfRows(10, withRowType: "WWCRow");
![Page 14: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/14.jpg)
Hit Run !
![Page 15: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/15.jpg)
MeetupRowController
![Page 16: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/16.jpg)
Change the class type as MeetupRowController
![Page 17: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/17.jpg)
Add meetup.json and meetup.swift (Shared folder) [ { "startTime": "10:00 AM", "endTime": "12:00 PM", "title": "Python Meetup", }, { "startTime": "12:00 PM", “endTime": "2:00 PM", "title": "iOS Meetup", }, { "startTime": "2:00 PM", "endTime": "4:00 PM", "title": "WatchOS Meetup", }, { "startTime": "4:00 PM", "endTime": "6:00 PM", "title": "Android Meetup", }, { "startTime": "6:00 PM", "endTime": "8:00 PM", "title": "Java Meetup", }]
class Meetup { let title: String let starttime: String let endtime: String class func allMeetups() -> [Meetup] {
var meetups = [Meetup]()if let path = NSBundle.mainBundle().pathForResource("Meetup", ofType: "json"),
let data = NSData(contentsOfFile: path) { do { let json = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments) as! [Dictionary<String, String>] for dict in json { let meetup = Meetup(dictionary: dict) meetups.append(meetup) } } catch { print(error) }
}return meetups
} init( title: String, starttime: String, endtime: String) {
self.title = titleself.starttime = starttimeself.endtime = endtime
} convenience init(dictionary: [String: String]) {
let title = dictionary["title"]!let starttime = dictionary["startTime"]!let endtime = dictionary["endTime"]!self.init(title: title, starttime: starttime, endtime: endtime)
}}
![Page 18: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/18.jpg)
Add files and add them to app and extension target
![Page 19: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/19.jpg)
Configure the labels on MeetupRowControllerclass MeetupRowController: NSObject {
@IBOutlet var timeLabel: WKInterfaceLabel!@IBOutlet var titleLabel: WKInterfaceLabel!
// 1var meetup: Meetup? {
// 2 Add a property observer that is triggered whenever the property is set; didSet {
// 3 Check of meetup is not nil if let meetup = meetup {
// 4 configure the labels using the relevant properties of meetup timeLabel.setText(meetup.starttime) titleLabel.setText(meetup.title) } } }}
![Page 20: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/20.jpg)
ScheduleInterfaceControllervar meetups = Meetup.allMeetups()
override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context) // Set up a Row count WWCMeetupTable.setNumberOfRows(meetups.count, withRowType: "WWCRow"); // Add data for each row for index in 0..<WWCMeetupTable.numberOfRows { if let controller = WWCMeetupTable.rowControllerAtIndex(index) as? MeetupRowController { controller.meetup = meetups[index] } }}
![Page 21: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/21.jpg)
Hit Run!
![Page 22: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/22.jpg)
Add new Interface controller and add design it.● Change Identifier and name it
as “Meetup”● Copy a image called static
maps into the project and assign it to the image.
● Create a group and add 2 buttons to it - YES & NO
![Page 23: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/23.jpg)
MeetupInterfaceControllerclass MeetupInterfaceController: WKInterfaceController {
@IBOutlet var timeLabel: WKInterfaceLabel!@IBOutlet var titleLabel: WKInterfaceLabel!
// 1
var meetup: Meetup? {
// 2 didSet {
// 3 if let meetup = meetup {
// 4 timeLabel.setText("\(meetup.starttime) to \(meetup.endtime)") titleLabel.setText(meetup.title) } }
}
override func awakeWithContext(context: AnyObject?) { super.awakeWithContext(context) if let meetup = context as? Meetup { self.meetup = meetup }
}
}
![Page 24: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/24.jpg)
ScheduleInterfaceControllerAdd a method didSelectRowAtIndex to push a viewcontroller
override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) { let meetup = meetups[rowIndex] presentControllerWithName("Meetup", context: meetup)}
![Page 25: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/25.jpg)
Hit Run!
![Page 26: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/26.jpg)
![Page 27: Learn watchOS Programming!](https://reader031.vdocument.in/reader031/viewer/2022030301/587ecc081a28abf37b8b7167/html5/thumbnails/27.jpg)