Skip to content

Instantly share code, notes, and snippets.

Avatar

Nikolay Kasyanov nikolaykasyanov

View GitHub Profile
@nikolaykasyanov
nikolaykasyanov / Example.swift
Last active Sep 27, 2019
A property wrapper that creates subject-backed observers (RxSwift)
View Example.swift
class ViewModel {
init() {
// accessing underlying subject:
$buttonTapped
.asObservable()
...
}
// look ma, no explicit subject property
View do you even retain self.md

Self в Swift и Objective-C

Дисклеймер: речь идёт об однопоточном коде, оставим ужасы параллельного исполнения за скобками. Также не рассматривается возможность overrelease.

Objective-C

Объект точно не ритейнится на время выполнения его метода, пруфы:

View DoYouEvenRetainSelf.m
#import <Foundation/Foundation.h>
@interface Node: NSObject
@property (nonatomic, weak) Node *parent;
@property (nonatomic) NSArray *children;
@end
@implementation Node {
View DoYouRetainSelf.swift
import Foundation
class Child {
deinit {
print("Child.deinit")
}
var parent: Parent?
func removeFromParent() {
@nikolaykasyanov
nikolaykasyanov / cmake.rb
Created Feb 4, 2019
CMake 3.12.4 formula
View cmake.rb
class Cmake < Formula
desc "Cross-platform make"
homepage "https://www.cmake.org/"
url "https://cmake.org/files/v3.12/cmake-3.12.4.tar.gz"
sha256 "5255584bfd043eb717562cff8942d472f1c0e4679c4941d84baadaa9b28e3194"
head "https://cmake.org/cmake.git"
bottle do
cellar :any_skip_relocation
sha256 "7bcd5ae043d2a6fd5983b026ccdc70b7594e0dbe9de4d367cfcead7edf3c8596" => :mojave
View Dependencies.swift
protocol RemoteAPIDelegate: class {
func remoteAPIDidLoadPosts(_ posts: NSArray)
}
class RemoteAPI {
weak var delegate: RemoteAPIDelegate?
func loadPosts() {
View ExternalService.swift
protocol ReachabilityDelegate: class {
func reachabilityDidChange(_ reachable: Bool)
}
class Reachability {
weak var delegate: ReachabilityDelegate?
}
class Model: ReachabilityDelegate {
func reachabilityDidChange(_ reachable: Bool) {
@nikolaykasyanov
nikolaykasyanov / C138FB1B-8C83-477C-B33C-05551516167A.codesnippet
Last active Nov 27, 2016
__auto_type autocompletion snippet for Xcode 8+. Just put it in ~/Library/Developer/Xcode/UserData/CodeSnippets/ and then start typing aut... in Xcode.
View C138FB1B-8C83-477C-B33C-05551516167A.codesnippet
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDECodeSnippetCompletionPrefix</key>
<string>auto</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>CodeBlock</string>
</array>
View mfb_latest_hockey_build.rb
require 'json'
require 'net/http'
module Fastlane
module Actions
class MfbLatestHockeyBuildAction < Action
def self.run(config)
host_uri = URI.parse('https://rink.hockeyapp.net')
http = Net::HTTP.new(host_uri.host, host_uri.port)
http.use_ssl = true
View AssociatedHype.swift
public protocol DBWorker2 {
associatedtype S: SequenceType
func fetchObjectsFromStorage(type: S.Generator.Element.Type) -> Observable<S.Generator.Element>
func saveObjectsToStorage(objects: S) -> Observable<Void>
}
public class DBWorker2Impl: DBWorker2 {
public func fetchObjectsFromStorage(type: Item.Type) -> Observable<Item> {
return Observable()