Skip to content

Instantly share code, notes, and snippets.

@takashi1975
takashi1975 / BallTap.cs
Created May 5, 2018 15:52
[Unity] RayCast
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BallTap : MonoBehaviour, TapBehaviour {
/** タッチしたとき */
public void TapDown(ref RaycastHit hit) {
Debug.Log("TapDown : " + hit);
override func viewWillDisappear(_ animated: Bool) {
/**
* UINavigationControllerの戻る[back]処理のイベントを取得する方法
* https://qiita.com/syamaoka/items/509ff50fcab485347600
* ... viewWillDisappearが呼ばれる時に、戻る処理を行っていれば、NavigationControllerのviewControllersの中にselfは存在していない
*/
if let viewControllers = self.navigationController?.viewControllers {
let existsSelfInViewControllers = viewControllers.filter{$0 == self}.count == 0
if existsSelfInViewControllers {
@takashi1975
takashi1975 / MapViewController.swift
Last active March 15, 2018 07:43
Swift4 NotificationCenter, KVO(KeyValueObserver) のコード例
/**
* KVO (Key Value Observer)
*
* GMSMapView (GoogleMap) の myLocation (CLLocation) の内容が変化したら...を取得
*/
import UIKit
import GoogleMaps
import CoreLocation
@takashi1975
takashi1975 / sample.swift
Last active March 5, 2018 05:36
Swift4 アラートの表示
//警告表示
internal alertTest() {
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
let defaultAction = UIAlertAction(title: "OK", style: .default) {
(action) in
print("OK")
}
alert.addAction(defaultAction)
@takashi1975
takashi1975 / sample.swift
Last active February 20, 2018 09:49
Swift4 クロージャーの宣言?に名前をつけたい
/**
* https://stackoverflow.com/questions/24077428/how-do-i-declare-typedef-in-swift
*/
//やりたかったこと
typealias FunctionClosure = (_ value: Int) -> Void
fileprivate var _closure: FunctionClosure? = nil
@takashi1975
takashi1975 / sample.swift
Last active February 13, 2018 05:40
swift4 abs
class sample {
/**
* メモ
* 標準の abs ... abs(Int32) だけなので... Int16 も扱える abs を Generics で試してみた。
*
* Generics の 型制限 をできないものかと...ググると SignedNumeric, SignedInteger を指定できる様子。
* ただ... SignedNumeric を指定すると (x < 0) の比較で エラーになるため 整数のみを指定
* Float などもまとめて処理できたらいいな...と思ったが...とりあえず見送り
*/
@takashi1975
takashi1975 / ViewController.swift
Last active January 30, 2018 04:13
Swift4 TableView Sample (備忘録)
//
// ViewController.swift
// Sample
//
import UIKit
// MARK: -
extension ViewController {
@takashi1975
takashi1975 / UITableViewController (delegate).swift
Last active January 16, 2018 06:16
UITableViewCell をタップしている間だけ選択状態にしたい (指を離したら解除)
/**
* UITableViewController を継承している場合を想定した例
*/
extension xxxTableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//セルの作成
let cell = UITableViewCell(style: .value1, reuseIdentifier: "cell")
//Configure the cell...
@takashi1975
takashi1975 / ViewController.swift
Created January 15, 2018 22:18
添付ファイル付きメール送信例
/**
* メールの送信 ... 大まかには 以下の記事を参考
* https://qiita.com/kobaboy/items/1d8a5c01baf299a8573b
*
* Documentフォルダの realmファイル を添付したくて試した時のメモ
*/
extension ViewController: MFMailComposeViewControllerDelegate {
fileprivate func sendMail(subject: String, message: String) {
@takashi1975
takashi1975 / auto_increment_id.swift
Last active December 10, 2017 23:47
Swift4 Realm
//https://stackoverflow.com/questions/39579025/auto-increment-id-in-realm-swift-3-0
//プライマリキーとして次の値を取得
public static func getNextId(_ object: Object) -> Int {
//インスタンスからクラスを取得
let model = type(of: object)
//Realm
let realm = try! Realm()