Files
flipper/iOS/SampleSwift/SampleSwift/CommunicationDemoViewController.swift
Andres Suarez 54ebb44dda Tidy up Flipper license headers [2/2]
Reviewed By: passy

Differential Revision: D17863710

fbshipit-source-id: 5b249bdd1c06d3a526b250b035b797d0c8e796eb
2019-10-11 13:46:45 -07:00

48 lines
1.4 KiB
Swift

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import UIKit
import FlipperKit
class CommunicationDemoViewController: UIViewController, UITableViewDataSource, FlipperKitExampleCommunicationResponderDelegate {
@IBOutlet weak var messageField: UITextField!
@IBOutlet weak var tableView: UITableView!
var messageArray: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
FlipperKitExamplePlugin.sharedInstance()?.delegate = self
}
@IBAction func tappedTriggerNotification(_ sender: UIButton) {
FlipperKitExamplePlugin.sharedInstance()?.triggerNotification();
}
@IBAction func tappedSendMessage(_ sender: UIButton) {
if let message = self.messageField.text {
FlipperKitExamplePlugin.sharedInstance()?.sendMessage(message);
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "reusableCell", for: indexPath)
cell.textLabel?.text = messageArray[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return messageArray.count;
}
func messageReceived(_ msg: String!) {
messageArray.append(msg)
DispatchQueue.main.async { [weak self] in
self?.tableView.reloadData();
}
}
}