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 tokenParts = deviceToken.map { data -> String in | |
| return String(format: "%02.2hhx", data) | |
| } | |
| let token = tokenParts.joined() | |
| print("Device Token: \(token)") |
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 sendToSlack() { | |
| let slackUrl = "" | |
| guard let url = URL(string: slackUrl) else { | |
| print("Error: cannot create URL") | |
| return | |
| } | |
| guard let position = lastPosition else { |
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
| protocol Payable { | |
| func calculateWages() -> Int | |
| } | |
| extension Payable { | |
| func calculateWages() -> Int { | |
| return 10000 | |
| } | |
| } |
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
| import UIKit | |
| // ********************************* | |
| // ************** MAP ************** | |
| // ********************************* | |
| // Классический вариант | |
| func lengthOf(strings: [String]) -> [Int] { | |
| var result = [Int]() | |
| for string in strings { |
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
| private func randomColor() -> UIColor { | |
| return UIColor(red: CGFloat(arc4random()) / CGFloat(UInt32.max), | |
| green: CGFloat(arc4random()) / CGFloat(UInt32.max), | |
| blue: CGFloat(arc4random()) / CGFloat(UInt32.max), | |
| alpha: 1.0) | |
| } |
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
| import UIKit | |
| public class Human: NSObject { | |
| @objc dynamic public var firstName = "*****" | |
| @objc dynamic public var lastName = "*****" | |
| @objc dynamic public var age = 0 | |
| @objc dynamic public var hobby = "*****" | |
| @objc dynamic public var university = "*****" | |
| @objc dynamic public var sportLeague = "*****" |
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 checkPhoneNumber(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { | |
| let validationSet = NSCharacterSet.decimalDigits.inverted | |
| let components = string.components(separatedBy: validationSet) | |
| guard components.count == 1 else { return false } | |
| guard var newString = (textField.text as NSString?)?.replacingCharacters(in: range, with: string) else { return false } | |
| let validComponents = newString.components(separatedBy: validationSet) |
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
| list = [9, 6, 7, 3, 42, 2, 78, 4, 5, 67, 98, 1] | |
| func quickSort2 <T: Comparable> (_ list: [T]) -> [T] { | |
| if list.count == 0 { | |
| return [] | |
| } | |
| let pivot = list[0] | |
| let sublist = list.count > 1 ? list[1..<list.count] : [] |
NewerOlder