This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; init.el | |
;; show line number | |
(require 'linum) | |
(global-linum-mode) | |
;; show and hide line number with F9 | |
(global-set-key [f9] 'linum-mode) | |
;; Language |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 列挙型 | |
enum Direction: Int { | |
// 実数値をそれぞれの定数に設定(Up = 0, Right = 1, ...) | |
case Up = 0, Right, Down, Left | |
// タイププロパティ | |
static var defaultDirection = Direction.Up | |
// イニシャライザ | |
init() { | |
self = Direction.defaultDirection | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Ounce { | |
var mL: Double = 0.0 | |
static let ounceUS = 29.5735 // 1オンス(アメリカ) | |
init(ounce: Double) { | |
self.ounce = ounce | |
} | |
var ounce: Double { | |
get { | |
return mL / Ounce.ounceUS | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 構造体 | |
struct FruitsMenu { | |
let menu = ["apple", "orange", "grape"] // 変更不可 | |
var submenu = ["banana", "peach", "pineapple"] // 変更可能 | |
let count = 6 | |
subscript (i: Int) -> String { | |
get { | |
return i < 3 ? menu[i] ] submenu[i - 3] | |
} | |
set { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//POSTされた生データ(JSON)を取得 | |
$json_string = file_get_contents('php://input'); | |
//JSONを、PHPで扱える配列(元がNSDictionaryなので連想配列)に変換 | |
$obj = json_decode($json_string); | |
//連想配列して入っているデータをそれぞれ変数に格納 | |
$id = $obj -> {'id'}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func sendData() { | |
// 今回はDictionary(Map)としてPHP側にデータをPOSTする | |
var submitDic = NSMutableDictionary() | |
submitDic.setObject("1", forKey: "id") | |
submitDic.setObject("hoge", forKey: "name") | |
// DictionaryをNSData型に変換してRequestに付与する | |
var submitData = NSJSONSerialization.dataWithJSONObject(submitDic, options: NSJSONWritingOptions.PrettyPrinted, error: &error) | |
if (error != nil) { | |
println(error?.localizedDescription) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$device_token = $_POST['DeviceToken']; // POSTの中の"DeviceToken"はあらかじめ送る方のコード(Swift)と統一しないといけない | |
echo "$device_token"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { | |
/* get device token */ | |
var characterSet = NSCharacterSet(charactersInString: "<>") // <>と" "(空白)を取る | |
var deviceTokenString = (deviceToken.description as NSString).stringByTrimmingCharactersInSet(characterSet).stringByReplacingOccurrencesOfString(" ", withString: "") as String | |
sendToken(deviceTokenString) | |
} | |
func sendToken(var token: String) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
// Override point for customization after application launch. | |
// After iOS8, must call registerUserNotificationSettings first | |
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil)) | |
return true | |
} | |
/* フォアグラウンド(アプリが起動中)の場合ローカル通知が来ないので、アラートを出すなりする */ | |
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 基本的にはObjective-cと同じ構文 */ | |
func registerNotification() { | |
var localNotification = UILocalNotification() | |
localNotification.fireDate = self.myPicker?.todoDate | |
localNotification.timeZone = NSTimeZone.defaultTimeZone() | |
localNotification.alertBody = "TODO : " + inputText! + "の時間ですよ" | |
localNotification.alertAction = "OK" | |
localNotification.soundName = UILocalNotificationDefaultSoundName | |
UIApplication.sharedApplication().scheduleLocalNotification(localNotification) |