Skip to content

Instantly share code, notes, and snippets.

View MathVasc's full-sized avatar

Matheus de Vasconcelos MathVasc

View GitHub Profile
func widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) {
if activeDisplayMode == .expanded {
//1
preferredContentSize = CGSize(width: maxSize.width, height: maxSize.width)
} else if activeDisplayMode == .compact {
//2
preferredContentSize = maxSize
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Esta linha de código diz ao widget que seu modo de exibição é do tipo expanded
self.extensionContext?.widgetLargestAvailableDisplayMode = .expanded
}
import UIKit
import CoreSpotlight
import MobileCoreServices
class SLManager {
}
public static func setSpotLightIndexes(){
//1
let items = DAOItem.sharedInstance.fetchItems()
//2
var searchableItems = [CSSearchableItem]()
}
public static func setSpotLightIndexes(){
//.
//.
//.
for item in items {
//1
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeItem as String)
//2
attributeSet.keywords = ["Groceries", "Grocery", "List"]
public static func setSpotLightIndexes(){
//.
//.
//.
//1
CSSearchableIndex.default().indexSearchableItems(searchableItems) { (error) in
guard error == nil else {
print(error!.localizedDescription)
return
}
public static func setSpotLightIndexes(){
let items = DAOItem.sharedInstance.fetchItems()
var searchableItems = [CSSearchableItem]()
// deletando todos os itens
CSSearchableIndex.default().deleteAllSearchableItems { (error) in
guard error == nil else {
print(error!.localizedDescription)
return
}
public static func setSpotLightIndexes(){
let items = DAOItem.sharedInstance.fetchItems()
var searchableItems = [CSSearchableItem]()
// deletando todos os itens
CSSearchableIndex.default().deleteAllSearchableItems { (error) in
guard error == nil else {
print(error!.localizedDescription)
return
}
public static func saveContext() {
let context = persistentContainer.viewContext
if context.hasChanges {
do {
try context.save()
// Adicione esta linha
SLManager.setSpotLightIndexes()
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
@MathVasc
MathVasc / AddTarget.swift
Created May 23, 2020 14:56
Add target to UIControll
let button = UIButton()
button.addTarget(self, action: #selector(goToNext), for: .touchUpInside)
@objc private func goToNext() {
...
}