[Solved] How do you find something in a dictionary without knowing the name of the dictionary

// A good, more object oriented way- struct Fruit{ var name: String var cost: Double var nutrition: Int } let fruitsDataHolder = [ Fruit(name: “Apple”, cost: 10.0, nutrition: 5), Fruit(name: “Banana”, cost: 15.0, nutrition: 10) ] func getFruitsCost(fruits: [Fruit]) -> Double{ var totalCost = 0.0 for fruit in fruits{ totalCost += fruit.cost } return totalCost … Read more

[Solved] Swift NStask function

Try this: func commmand(argument: String) -> String { let task:NSTask = NSTask() let pipe:NSPipe = NSPipe() task.launchPath = “/bin/menubar” task.arguments = [argument] task.standardOutput = pipe task.launch() let handle = pipe.fileHandleForReading let data = handle.readDataToEndOfFile() let result_s = String(data: data, encoding: NSUTF8StringEncoding)! return result_s } print(commmand(“getip”)) 2 solved Swift NStask function