This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import CoreSpotlight | |
import MobileCoreServices | |
class SLManager { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static func setSpotLightIndexes(){ | |
//1 | |
let items = DAOItem.sharedInstance.fetchItems() | |
//2 | |
var searchableItems = [CSSearchableItem]() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static func setSpotLightIndexes(){ | |
//. | |
//. | |
//. | |
for item in items { | |
//1 | |
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeItem as String) | |
//2 | |
attributeSet.keywords = ["Groceries", "Grocery", "List"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static func setSpotLightIndexes(){ | |
//. | |
//. | |
//. | |
//1 | |
CSSearchableIndex.default().indexSearchableItems(searchableItems) { (error) in | |
guard error == nil else { | |
print(error!.localizedDescription) | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let button = UIButton() | |
button.addTarget(self, action: #selector(goToNext), for: .touchUpInside) | |
@objc private func goToNext() { | |
... | |
} |
OlderNewer