Skip to content

Instantly share code, notes, and snippets.

let mensagem: [String: Any] = ["Mensagem": "Hello Wacth!"]
WCSession.default.sendMessage(mensagem, replyHandler: nil, errorHandler: nil)
func share(items: [Any], withCompletion completion: @escaping () -> Void) {
let activityController = UIActivityViewController(activityItems: items, applicationActivities: nil)
activityController.popoverPresentationController?.sourceView = self.view
let completion: (UIActivityType?, Bool, [Any]?, Error?) -> Void = { activityType, didShare, anyStuff, error in
if let error = error {
//TODO: error handling
}
completion()
}
class JSHandler: NSObject, JSHandlerJSExport {
//MARK: Static
static func say(_ text: String) {
DispatchQueue.main.async {
if let a = (UIApplication.shared.delegate as! AppDelegate).stuffDoer {
a.doSay(text)
}
}
}
void tarefas(TDigrafo *D){
int i, j, *visitado = (int*) calloc(D->V, sizeof(int));
for (i = 0; i < D->A; i++) {
for (j = 0; j < D->A - i; j++) {
if (visitado[j] == 0 && outdeg(D, i) == 0) {
visitado[j] = 1;
printf("%d ",D->adj[j]->w);
}
}
}
int indeg(TDigrafo *D, int v){
int i, grau = 0;
for(i = 0; i < D->V; i++){ // vetor de listas
TNo *aux = D->adj[i];
while(aux){ // anda na lista
if (aux->w == v) {
grau++;
}
aux = aux->prox;
//método para verificar se existe caminho entre dois vértices em um grafo
//na primeira chamada, "length" tem de ser 0
int hasPath(TDigrafo *D, int start, int finish, int length){
if (length >= D->V) {//se o caminho atual tiver mais pontos do que vertices no grafo, algo de errado aconteceu
return 0
}
//descobrir para onde se pode ir a partir do início
TNo *aux = D->adj[start];
while( aux ){ // anda na lista
public func updateData(item: GroceryItem, completion: @escaping (Error?) -> Void) {
let data = CKRecord(recordType: "Item")
data.setValue(item.name, forKey: "Value")
data.setValue(item.completed, forKey: "Completed")
let modifyOperation = CKModifyRecordsOperation(recordsToSave: [data], recordIDsToDelete: [item.key!])
modifyOperation.savePolicy = .ifServerRecordUnchanged
self.publicDB.add(modifyOperation)
}
public func deleteData(item: GroceryItem, completion: @escaping (Error?) -> Void) {
self.publicDB.delete(withRecordID: item.key!) { (record, error) in
completion(error)
}
}
public func saveData(item: GroceryItem, completion: @escaping () -> Void) {
let data = CKRecord(recordType: "Item")
data.setValue(item.name, forKey: "Value")
data.setValue(item.completed, forKey: "Completed")
self.publicDB.save(data) { (record, errod) in
print("saved \(item.name) to iCloud")
completion()
}
}
public func getData(completion: @escaping ([GroceryItem]) -> Void) {
let predicate = NSPredicate(value: true)
let query = CKQuery(recordType: "Item", predicate: predicate)
var itens: [GroceryItem] = []
self.publicDB.perform(query, inZoneWith: nil) { (records, error) in
if (records?.count)! > 0 {
for record in records! {
itens.append(GroceryItem(record: (record)))
}