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
@propertyWrapper | |
class UserDefaultEnumKey<T, R: RawRepresentable> where R.RawValue == String { | |
let key: String | |
let defaultValue: T | |
init(_ key: R, defaultValue: T) { | |
self.key = key.rawValue | |
self.defaultValue = defaultValue | |
} | |
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 reverseList(_ head: ListNode?) -> ListNode? { | |
var prev: ListNode? = nil | |
var curr = head | |
while curr != nil { | |
let next = curr?.next | |
curr?.next = prev | |
prev = curr | |
curr = next | |
} |
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 middleNode(_ head: ListNode?) -> ListNode? { | |
var slow = head | |
var fast = head | |
while fast != nil && fast?.next != nil { | |
slow = slow?.next | |
fast = fast?.next?.next | |
} | |
return slow | |
} |
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 | |
protocol SomeExtension { | |
func doSomething() | |
} | |
extension SomeExtension { | |
func doSomething() { | |
print("Do nothing or error") | |
} | |
} |
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
String(format: "%2$@, %1$@", "one", "two") |
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 | |
import ReactiveCocoa | |
import ReactiveSwift | |
public class ComponentLabel: UILabel { | |
public override init(frame: CGRect) { | |
super.init(frame: frame) | |
backgroundColor = .yellow | |
} |
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
Pod::Spec.new do |s| | |
s.name = 'MySDK' | |
s.version = '1.0.0' | |
s.summary = 'A really cool SDK that logs stuff.' | |
s.homepage = 'http://example.com/' | |
s.author = { 'Name' => 'sdk@example.com' } | |
s.license = { :type => 'Apache-2.0', :file => 'LICENSE' } | |
s.platform = :ios |
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
{% for type in types.implementing.PublicInit %} | |
extension {{ type.name }} { | |
public init({% for var in type.storedVariables %}{{var.name}}: {{var.typeName}}{% if not forloop.last %}, {% endif %}{% endfor %}) { | |
{% for var in type.storedVariables %} | |
self.{{var.name}} = {{var.name}} | |
{% endfor %} | |
} | |
} | |
{% endfor %} |
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
// Binary search for shifted array | |
func binarySearch<T: Comparable>(arr: [T], target: T, range: Range<Int>) -> Int? { | |
if range.lowerBound >= range.upperBound { return nil } | |
let mid = range.lowerBound + (range.upperBound - range.lowerBound)/2 | |
if arr[mid] == target { | |
return mid | |
} else if arr[mid] > target { | |
return binarySearch(arr: arr, target: target, range: range.lowerBound..<mid) |
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
typealias UploadResult = (Data?, URLResponse?, Error?) | |
func uploadImage(url: URL, image: UIImage, token: String, completion: @escaping (UploadResult) -> Void) { | |
let session = URLSession(configuration: .default) | |
let request = uploadImageRequest(url: url, image: image, token: token) | |
session.dataTask(with: request, completionHandler: completion).resume() | |
} | |
private func uploadImageRequest(url: URL, image: UIImage, token: String) -> URLRequest { | |
var request = URLRequest(url: url) |
NewerOlder