Skip to content

Instantly share code, notes, and snippets.

if isToHideWidget
{
NCWidgetController.widgetController().setHasContent(false, forWidgetWithBundleIdentifier: "YOUR_TODAY_EXTENSION_BUNDLE_IDENTIFIER")
}
else
{
NCWidgetController.widgetController().setHasContent(true, forWidgetWithBundleIdentifier: "YOUR_TODAY_EXTENSION_BUNDLE_IDENTIFIER")
}
override func viewDidLoad()
{
super.viewDidLoad()
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
button.addTarget(self, action: #selector(buttonClick), for: .touchUpInside)
}
@objc func buttonClick() //Add @objc in method definition
{
class BaseCell: UITableViewCell
{
func isBlank() -> Bool
{
return false
}
func isValid() -> Bool
{
return false
let attributedString = NSAttributedString(string: "This is an attributed string.",
attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 10.0)])
@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let deleteAction = UIContextualAction(style: .destructive, title: "Add") { (action, view, handler) in
print("Add Action Tapped")
}
deleteAction.backgroundColor = .green
let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
return configuration
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
{
let deleteAction = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexpath) in
print("Delete Action Tapped")
}
deleteAction.backgroundColor = .red
return [deleteAction]
}
@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { (action, view, handler) in
print("Delete Action Tapped")
}
deleteAction.backgroundColor = .red
let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
configuration.performsFirstActionWithFullSwipe = false //HERE..
return configuration
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool
{
return true
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
{
//An array of UITableViewRowAction objects representing the actions for the row.
}
struct Photo: Codable
{
//String, URL, Bool and Date conform to Codable.
var title: String
var url: URL
var isSample: Bool
//The Dictionary is of type [String:String] and String already conforms to Codable.
var metaData: [String:String]
let photoObject = Photo(title: "Hibiscus", url: URL(string: "https://www.flowers.com/hibiscus")!, isSample: false, metaData: ["color" : "red"], type: .flower, size: Size(width: 200, height: 200))
let encodedData = try? JSONEncoder().encode(photoObject)