A Swift library that aims to make Swift usage similar to Python
Add the following dependency to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/YassineLafryhi/Swifthon.git", from: "0.9.4")
]
import Foundation
import Swifthon
let user = Swifthon.os.getlogin()
let path = "/Users/\(user)/Desktop/demo.txt"
var f = Swifthon.open(path, "a")!
f.write("Now the file has more content !")
f.close()
f = Swifthon.open(path, "r")!
var content = f.read()
print(content)
f.close()
import Foundation
import Swifthon
let data = try await Swifthon.requests.get("https://jsonplaceholder.typicode.com/todos")
let json = try Swifthon.json.loads(data)
for item in json {
print(item["title"])
}
import Foundation
import Swifthon
let now = Swifthon.datetime.now()
let formatted = now.strftime("dd-MM-yyyy HH:mm:ss")
print(formatted)
import Foundation
import Swifthon
print("Value of pi: \(Swifthon.math.pi)")
print("Value of e: \(Swifthon.math.e)")
print("Square root of 25: \(Swifthon.math.sqrt(25))")
print("Factorial of 3: \(Swifthon.math.factorial(3))")
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request