Skip to content

Instantly share code, notes, and snippets.

@MrSmart00
MrSmart00 / Publisher+Materialize.swift
Created Jun 30, 2020
Swift Combine: Add Materialize Publisher with separatable function on Publishers. And add ignore Nil operation on Publisher.
View Publisher+Materialize.swift
import Foundation
import Combine
public extension Publishers {
enum Event<T, E: Error> {
case value(T)
case failure(E)
case finished
var value: T? {
@MrSmart00
MrSmart00 / PublishRelay+PropertyWrapper.swift
Created Jun 4, 2020
PublishRelay with Property Wrapper
View PublishRelay+PropertyWrapper.swift
import Foundation
import RxSwift
import RxCocoa
@propertyWrapper
struct WrappedPublishRelay<Value> {
private let value: AnyObserver<Value>
private let observable: Observable<Value>
init(_ relay: PublishRelay<Value> = .init()) {
@MrSmart00
MrSmart00 / MyExtension.extension.swift
Last active Jan 23, 2019
How to use a Modern swifty extensions
View MyExtension.extension.swift
public class MyExtension<T> {
let obj: T
public init(base: T) {
self.obj = base
}
}
@MrSmart00
MrSmart00 / UIColor.extension.swift
Last active Dec 3, 2018
UIColor Extension: create with a hex string @Swift4.2
View UIColor.extension.swift
extension UIColor {
convenience init(hex: String) {
let hexStr = hex.lowercased().replacingOccurrences(of: "0x", with: "")
let hexmap = hexStr.map { String($0) }
+ Array(repeating: "0", count: max(6 - hexStr.count, 0))
+ Array(repeating: "f", count: max(8 - max(6, hexStr.count), 0))
let split = stride(from: 0, to: hexmap.count, by: 2)
.map { hexmap[$0..<$0+2]
.reduce(into: String()) { $0 += $1 } }
@MrSmart00
MrSmart00 / Enemy.cs
Last active Aug 29, 2015
Unity4.6オープンβでチュートリアルのShoothing Game作ってみる ref: http://qiita.com/MrSmart/items/b7e4eeebd1435fe8861b
View Enemy.cs
using UnityEngine;
using System.Collections;
public class Enemy : Spaceship {
// ヒットポイント
public int hp = 1;
// 弾を撃つかどうか
public bool canShot;
You can’t perform that action at this time.