Skip to content

Instantly share code, notes, and snippets.

View aleos's full-sized avatar
🚀
Bright future ahead

Alexander Ostrovsky aleos

🚀
Bright future ahead
View GitHub Profile
@aleos
aleos / fonts-list.swift
Created August 7, 2022 17:26
Get available fonts. It's very helpful to find fonts' program ids
for family in UIFont.familyNames.sorted() {
let names = UIFont.fontNames(forFamilyName: family)
print("Family: \(family) Font names: \(names)")
}
@aleos
aleos / button-pinned-to-keyboard.swift
Last active August 7, 2022 15:00
Attach the button to the keyboard
struct ContentView: View {
@State var text = "Test"
var body: some View{
NavigationView {
VStack {
TextField("enter email", text: .constant(""))
.textFieldStyle(.roundedBorder)
Spacer()
Button {} label: {
Text("Next")
@aleos
aleos / video-size-bytes.swift
Created June 13, 2016 10:34
Get video size in bytes
// AVAsset
let asset: AVAsset(URL: NSURL(string: "..."))
let assetSizeBytes = asset.tracksWithMediaType(AVMediaTypeVideo).first?.totalSampleDataLength
// File
let fileOnDiskSizeBytes = try! NSFileManager.defaultManager().attributesOfItemAtPath("...")[NSFileSize] as! NSNumber
@aleos
aleos / copyable.swift
Last active August 7, 2022 15:01
Copyable protocol to be able to copy classes
protocol Copyable {
init(copy:Self)
}
extension Copyable {
func copy() -> Self {
return Self.init(copy: self)
}
}
@aleos
aleos / pattern-matching-type.swift
Created January 30, 2016 11:50
Swift pattern matching for types
let numbers: [Any] = [Int(3), Double(4.0), Int(7)]
for number in numbers {
switch number {
case is Int:
print("Integer")
case is Double:
print("Double")
default: break
}
}