Skip to content

Instantly share code, notes, and snippets.

View keitaito's full-sized avatar

Keita Ito keitaito

View GitHub Profile
@keitaito
keitaito / BinarySearch.m
Last active September 10, 2015 07:22
BinarySearch.m
//
// BinarySearch.m
// KIObjcAlgorithms
//
// Created by Keita on 9/8/15.
// Copyright (c) 2015 Keita Ito. All rights reserved.
//
#import "BinarySearch.h"
@keitaito
keitaito / SelectionSort.m
Created September 11, 2015 08:31
SelectionSort
//
// SelectionSort.m
// KIObjcAlgorithms
//
// Created by Keita on 9/11/15.
// Copyright © 2015 Keita Ito. All rights reserved.
//
#import "SelectionSort.h"
@keitaito
keitaito / getClassNameOfAnObject.swift
Created March 6, 2016 09:46
How to get the class name of an object in Swift 2
struct Archvier<T: AnyObject> {
static func getStringOfClassName(object: T) -> String {
return String(T)
}
}
// NSStringFromClass() didn't work with my custom class, even it is a subclass of NSObject.
@keitaito
keitaito / UpdateAddressOfRecordInAddressBook.m
Last active March 8, 2016 09:03
Update a record's address in address book using ABAddressBook framework.
// Prepare address values. These values will be saved in a record in iPhone's address book.
NSString *city = @"Yokohama";
NSString *state = @"Kanagawa"
NSString *country = @"Japan";
// Get a record ID.
ABRecordID recordID = self.recordID; // Assume you have a recordID.
// Create dictionary for address.
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
@keitaito
keitaito / NSCodingProtocolConformedImplementationInSwift.swift
Created March 11, 2016 07:57
How to conform NSCoding protocol in Swift
// NSCoding Protocol conformed implementation
// Reference: http://stackoverflow.com/questions/20539619/storing-custom-objects-with-core-data
import Foundation
class MyClass: NSObject, NSCoding {
let name: String
init(name: String) {
self.name = name
@keitaito
keitaito / CodeSnippetForInteractivePlayground.swift
Created April 3, 2016 11:07
Code snippet for Interactive Playground
//: Playground - noun: a place where people can play
import UIKit
import XCPlayground
class SomeView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
let button = UIButton(frame: self.bounds)
@keitaito
keitaito / ShorhandArgumentNamesExample.swift
Last active April 21, 2016 07:54
ShorhandArgumentNamesExample.swift - Run this code on Playground
//: Playground - noun: a place where people can play
let tuples = [("A", "あ"), ("I", "い"), ("U", "う"), ("E", "え"), ("O", "お")]
print("With argument list")
tuples.forEach { (eng, jpn) in
print(eng)
print(jpn)
}
@keitaito
keitaito / swift utils build-script --test overall tests result with swiftenv.txt
Last active September 19, 2016 06:14
swift/utils/build-script -t overall tests result
********************
Testing Time: 815.15s
********************
Failing Tests (346):
Swift(macosx-x86_64) :: SILOptimizer/specialize_partial_apply.swift
Swift(macosx-x86_64) :: SILOptimizer/let_properties_opts_runtime.swift
Swift(macosx-x86_64) :: SILOptimizer/capture_propagation_linkage.swift
Swift(macosx-x86_64) :: stdlib/BridgeIdAsAny.swift.gyb
Swift(macosx-x86_64) :: multifile/error-type/two-modules/main.swift
Swift(macosx-x86_64) :: multifile/synthesized-accessors/one-module-public/main.swift
2016-12-25 01:39:56.726 RealmSantaTracker[68899:4488336] Sync: Opening Realm file: /Users/keitaito/Library/Developer/CoreSimulator/Devices/410BBEF4-54EF-412E-8C8C-ECE9CDE1C5AA/data/Containers/Data/Application/D1047B1A-5CFC-4029-AA1B-2EA45A64C563/Documents/realm-object-server/771b9ee46cf86cd5b6b28a77d3aa688e/realm%3A%2F%2F162.243.150.99%3A9080%2Fsanta
2016-12-25 01:39:56.728 RealmSantaTracker[68899:4488336] Sync: Connection[1]: Session[1]: Starting session for '/Users/keitaito/Library/Developer/CoreSimulator/Devices/410BBEF4-54EF-412E-8C8C-ECE9CDE1C5AA/data/Containers/Data/Application/D1047B1A-5CFC-4029-AA1B-2EA45A64C563/Documents/realm-object-server/771b9ee46cf86cd5b6b28a77d3aa688e/realm%3A%2F%2F162.243.150.99%3A9080%2Fsanta'
2016-12-25 01:39:56.729 RealmSantaTracker[68899:4488336] Sync: Connection[1]: Resolving '162.243.150.99:9080'
2016-12-25 01:39:56.733 RealmSantaTracker[68899:4488336] Sync: Connection[1]: Connecting to endpoint '162.243.150.99:9080' (1/1)
2016-12-25 01:39:56.752 RealmSantaTracker[68899:4
// Updated to Swift 3 syntax.
func mapScalarValues(s: String, f: (UInt32) -> UInt32) -> String {
let scalars = Array(s.unicodeScalars)
let encrypted = scalars.map { x in
Character(UnicodeScalar(f(x.value))!)
}
return String(encrypted)
}