Skip to content

Instantly share code, notes, and snippets.

@tad-iizuka
tad-iizuka / gist:ca8a4abdd948485c1ad4796eb48f602b
Created September 21, 2016 08:13
Read Core Data with Swift3.0
func loadCoreData() {
let fetchRequest: NSFetchRequest<Manager> = Manager.fetchRequest()
do {
self.item = try (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext.fetch(fetchRequest)
} catch {
print(String(format: "Error %@: %d",#file, #line))
}
}
func loadCoreData() {
let fetchRequest: NSFetchRequest<Manager> = Manager.fetchRequest()
do {
self.item = try (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext.fetch(fetchRequest)
} catch {
print(String(format: "Error %@: %d",#file, #line))
}
}
@tad-iizuka
tad-iizuka / add
Created September 22, 2016 12:00
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let manager = Manager(context: context)
let textField = alert.textFields![0] as UITextField
if textField.text != "" {
manager.name = textField.text
} else {
manager.name = String(self.item.count+1)
}
manager.date = NSDate()
let fetchRequest: NSFetchRequest<Staff> = Staff.fetchRequest()
if self.manager != nil {
fetchRequest.predicate = NSPredicate(format: "manager = %@", self.manager!)
}
do {
item = try (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext.fetch(fetchRequest)
} catch {
print(String(format: "Error %@: %d",#file, #line))
}
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
for obj in self.item {
context.delete(obj)
}
do {
try context.save()
} catch {
print(String(format: "Error %@: %d",#file, #line))
}
@tad-iizuka
tad-iizuka / gist:f5644933b55c91c78a0c729831a90fdd
Created November 3, 2016 04:34
AVAudioEngine Reverb On/Off
func reverbControl(onoff: Bool) {
let status = playerNode.isPlaying
offsetFrame = Int(self.slider.value)
if status {
playerNode.pause()
audioEngine.inputNode!.installTap(onBus: 0, bufferSize: AVAudioFrameCount(format.sampleRate * 0.4), format: format, block: { (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
let converter = AVAudioConverter.init(from: format, to: downFormat)
let newbuffer = AVAudioPCMBuffer(pcmFormat: downFormat,
frameCapacity: AVAudioFrameCount(downFormat.sampleRate * 0.4))
let inputBlock : AVAudioConverterInputBlock = { (inNumPackets, outStatus) -> AVAudioBuffer? in
outStatus.pointee = AVAudioConverterInputStatus.haveData
let audioBuffer : AVAudioBuffer = buffer
return audioBuffer
}
func startRecord() {
// 出力ファイルパスを初期化、録音中に設定
self.filePath = nil
self.isRec = true
// Audio Sessionを再生&録音モードに変更
try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord)
try! AVAudioSession.sharedInstance().setActive(true)
import requests
import json
import os
HEADER = {
'Content-type': 'application/json',
'Authorization': 'Bearer ' + 'Channel Access Token'
}
def lambda_handler(event, context):
UIView.setAnimationsEnabled(false)
button.setTitle("label", for: .normal)
button.layoutIfNeeded()
UIView.setAnimationsEnabled(true)