Skip to content

Instantly share code, notes, and snippets.

View 7gano's full-sized avatar

Norihisa Nagano 7gano

View GitHub Profile
@7gano
7gano / hoge.swift
Created February 5, 2016 07:03
NSURLComponentsというのができとってなぁ
let a = NSURLQueryItem(name: "a", value: "yes")
let b = NSURLQueryItem(name: "b", value: "no")
let urlComponents = NSURLComponents(string: "https://hoge.com")
urlComponents!.queryItems = [a, b]
urlComponents!.URL
=> "https://hoge.com?a=yes&b=no"
@7gano
7gano / CollectionViewCellに置いたUIButtonがウインクしちゃうよパトラッシュ.swift
Last active February 10, 2016 07:38
CollectionViewCellに置いたUIButtonがウインクしちゃうよパトラッシュ
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! ButtonCollectionViewCell
if let button = cell.button {
//アニメーションオフしてレイアウトしてアニメーションオンにするとOK
UIView.setAnimationsEnabled(false)
button.setTitle(String(indexPath.item), forState: UIControlState.Normal)
button.layoutIfNeeded()
UIView.setAnimationsEnabled(true)
}
@7gano
7gano / 平成.swift
Created September 7, 2016 06:27
今は平成28年だゾ!
let japaneaseCalendar = Calendar(identifier: Calendar.Identifier.japanese)
var dateFormatter = DateFormatter()
dateFormatter.calendar = japaneaseCalendar
dateFormatter.dateFormat = "GGyy"
dateFormatter.locale = Locale(identifier: "ja_JP")
dateFormatter.string(from: Date())
@7gano
7gano / AVAssetReaderAudioMixOutput.swift
Created August 1, 2017 04:23
AVAssetReaderAudioMixOutput
let asset = AVAsset(url: sourceFileURL)
let dict = [AVSampleRateKey:44100, AVFormatIDKey:kAudioFormatLinearPCM] as [String : Any]
assetReaderOutput = AVAssetReaderAudioMixOutput(audioTracks: asset.tracks, audioSettings: dict)
do {
assetReader = try AVAssetReader(asset: asset)
if assetReader.canAdd(assetReaderOutput) {
assetReader.add(assetReaderOutput)
assetReader.startReading()
}
//: Playground - noun: a place where people can play
import UIKit
class Hoge: NSObject, Comparable {
let text:String
init(text:String) {
self.text = text
}
//: Playground - noun: a place where people can play
import UIKit
class Hoge: Comparable, Hashable {
let text:String
init(text:String) {
self.text = text
}