This file contains 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
extension Array { | |
var powerset: [[Element]] { | |
guard count > 0 else { | |
return [[]] | |
} | |
// tail contains the whole array BUT the first element | |
let tail = Array(self[1..<endIndex]) | |
This file contains 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 googleChallenge(number: Int) { | |
func maximumNumberOfColumn(for n: Int) -> Int { | |
var result = 0 | |
while true { | |
result += 1 | |
if (result * (result + 1)) > (2 * n) { | |
return result - 1 | |
} | |
} |
This file contains 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
extension String { | |
var trimmed: String { | |
return self.trimmingCharacters(in: .whitespacesAndNewlines) | |
} | |
} | |
enum Errors: Error { |
This file contains 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 AClass: NSObject { | |
var name: String | |
var age: Int | |
init(name: String, age: Int) { | |
self.name = name | |
self.age = age | |
} | |
} |
This file contains 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
// | |
// MobileProvision.swift | |
// Testa | |
// | |
// Created by Omid Golparvar on 4/26/19. | |
// Copyright © 2019 Omid Golparvar. All rights reserved. | |
// | |
// | |
// MobileProvision.swift |
This file contains 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 Person: NSObject { | |
@objc dynamic | |
static func Initialize(copyOf instance: Person) -> Person { | |
print("Original Initialize(copyOf:).") | |
return .init(name: instance.name, age: instance.age) | |
} | |
var name: String | |
var age: Int |
This file contains 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
@IBAction func textFieldEditingChanged(_ sender: UITextField) { | |
guard let text = sender.text, !text.isEmpty else { return } | |
guard let newString = convertToPersian(from: text) else { return } | |
textField.text = newString | |
} | |
func convertToPersian(from string: String) -> String? { | |
let englishToPersianDictionary: [String: String] = [ | |
"0": "۰", |
This file contains 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
import Foundation | |
func isValidIBAN(_ rawString: String) -> Bool { | |
let string = rawString | |
.uppercased() | |
.filter({ ("A"..."Z" ~= $0) || "0"..."9" ~= $0 }) | |
guard string.count == 26 else { return false } | |
let newString = String(string.suffix(string.count - 4)) + String(string.prefix(4)) |
This file contains 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 isValidIranNationalCode(_ text: String) -> Bool { | |
let string = text.trimmingCharacters(in: .whitespacesAndNewlines) | |
guard !string.isEmpty, string.count == 10 else { return false } | |
let invalidStrings = [ | |
"0000000000", "1111111111","2222222222","3333333333","4444444444", | |
"5555555555", "6666666666","7777777777","8888888888","9999999999" | |
] | |
guard !invalidStrings.contains(string) else { return false } |
This file contains 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 extension UIBezierPath { | |
public static func ID_Initialize(square: CGRect, numberOfSides: UInt, cornerRadius: CGFloat) -> UIBezierPath? { | |
guard square.width == square.height | |
else { return nil } | |
let squareWidth = square.width | |
guard (numberOfSides > 0) && (cornerRadius >= 0.0) && (2.0 * cornerRadius < squareWidth) && !square.isInfinite && !square.isEmpty && !square.isNull |
OlderNewer