This file contains hidden or 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 mensagem: [String: Any] = ["Mensagem": "Hello Wacth!"] | |
WCSession.default.sendMessage(mensagem, replyHandler: nil, errorHandler: nil) |
This file contains hidden or 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 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() | |
} |
This file contains hidden or 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
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) | |
} | |
} | |
} | |
This file contains hidden or 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
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); | |
} | |
} | |
} |
This file contains hidden or 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
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; |
This file contains hidden or 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
//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 |
This file contains hidden or 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 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) | |
} |
This file contains hidden or 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 func deleteData(item: GroceryItem, completion: @escaping (Error?) -> Void) { | |
self.publicDB.delete(withRecordID: item.key!) { (record, error) in | |
completion(error) | |
} | |
} |
This file contains hidden or 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 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() | |
} | |
} |
This file contains hidden or 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 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))) | |
} |