Skip to content

Instantly share code, notes, and snippets.

View matsuda's full-sized avatar

Kosuke Matsuda matsuda

  • Tokyo, Japan
View GitHub Profile
@matsuda
matsuda / NotificationExtension.swift
Created March 8, 2017 02:29
Notification extensions in Swift 3
extension Notification {
// MARK: - Identifier
enum Identifier: String {
case DidChangeSession
}
// MARK: - UserInfoKey
enum UserInfoKey: String {
case Session
@matsuda
matsuda / memoryAddress.swift
Last active February 20, 2025 08:01
Get memory address in Swift
///
/// https://stackoverflow.com/a/29741007
///
let s = Struct() // Struct
withUnsafePointer(to: s) {
print(String(format: "%p", $0)
}
///
/// http://stackoverflow.com/a/36539213/226791
@matsuda
matsuda / Foo.swift
Last active September 20, 2019 02:22
Realm utilities
import RealmSwift
final class Foo: Object {
dynamic var code: String = UUID().uuidString
dynamic var timestamp: Date = Date()
override static func primaryKey() -> String? {
return "code"
}
///
/// MARK: - BadgeButton
///
class BadgeButton: UIButton {
let badgeLabel: BadgeLabel = BadgeLabel()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initialize()
}

Xcode7でiOS8端末にアクセスできるように

sudo ln -s /Applications/Xcode8_1.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/10.1\ \(14B72\) /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/10.1

simulatorにappをインストール

まだうまくいったことなし

@matsuda
matsuda / Configuration.swift
Created August 28, 2016 23:16
Alamofire + Himotoki
import Foundation
public struct Configuration {
public static var baseURL: NSURL {
return NSURL(string: "\(scheme)://\(host)\(scriptName)")!
}
private static var scheme: String {
return useSSL ? "https" : "http"
}
@matsuda
matsuda / UnwrappedNSNull.swift
Created July 12, 2016 02:24
NSNullを除去する
//
// UnwrappedNSNull.swift
// WeddingApps
//
// Created by Kosuke Matsuda on 2016/06/24.
// Copyright © 2016年 Appirits Inc. All rights reserved.
//
import Foundation
@matsuda
matsuda / API.swift
Last active February 15, 2017 06:38
Alamofire + Himotoki
//
// https://github.com/Alamofire/Alamofire#response-serialization-1
//
import Alamofire
import Himotoki
protocol ResponseObjectSerializable: Decodable {
}
@matsuda
matsuda / AppDelegate.swift
Last active November 12, 2017 07:41
log functions for application in Swift
import UIKit
#if DEBUG
func exceptionHandler(exception : NSException) {
NSLog("CRASH: %@", exception);
NSLog("Stack Trace: %@", exception.callStackSymbols);
// Internal error reporting
}
#endif
@matsuda
matsuda / xc_build_alert.sh
Last active May 15, 2018 16:21
Warning script in swift project
# http://bendodson.com/weblog/2014/10/02/showing-todo-as-warning-in-swift-xcode-project/
TAGS="TODO:|FIXME:|WARNING:"
echo "searching ${SRCROOT} for ${TAGS}"
# find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
find "${SRCROOT}/${PROJECT_NAME}" \( -name "*.swift" ! -type d \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"