Skip to content

Instantly share code, notes, and snippets.

View mtsd's full-sized avatar

Kosuke Matsuda mtsd

  • Tokyo, Japan
View GitHub Profile
@mtsd
mtsd / AppDelegate+APNs.swift
Created March 8, 2017 02:30
Implement APNs handling in Swift 3
import UserNotifications
import MuddlerKit
// MARK: - APNs utilities
extension AppDelegate {
func applicationWillRegisterForRemoteNotifications_compatible(_ application: UIApplication) {
if #available(iOS 10.0, *) {
applicationWillRegisterForRemoteNotifications(application)
} else {
@mtsd
mtsd / 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
@mtsd
mtsd / 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
@mtsd
mtsd / 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"
}
@mtsd
mtsd / Badge.swift
Last active October 14, 2017 06:44
///
/// 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をインストール

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

@mtsd
mtsd / 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"
}
@mtsd
mtsd / 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
@mtsd
mtsd / 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 {
}
@mtsd
mtsd / 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