Skip to content

Instantly share code, notes, and snippets.

View keitaito's full-sized avatar

Keita Ito keitaito

View GitHub Profile
@keitaito
keitaito / ReadAndWritePlistFile.m
Last active April 28, 2021 14:51
Read and Write Plist File in Objective-C, converted from Swift version written by Rebeloper http://rebeloper.com/read-write-plist-file-swift/
//
// ViewController.m
// ReadAndWritePlistFile
//
// Created by Keita on 3/3/15.
// Copyright (c) 2015 Keita Ito. All rights reserved.
// converted from Swift version written by Rebeloper http://rebeloper.com/read-write-plist-file-swift/
#import "ViewController.h"
@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 / GetValueFromCFDictionaryRef.m
Created March 9, 2016 08:45
Get value from CFDictionaryRef by converting it to NSDictionary.
+ (NSString *)getValueFromCFDictionaryRef {
// Assume you have record ID.
NSInteger recordID;
// Get a person record.
ABAddressBookRef addressBook = ABAddressBookCreate();
ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, recordID);
// Get addresses data from person. Watch out it's a multi-value property.
ABMultiValueRef addresses = ABRecordCopyValue(person, kABPersonAddressProperty);
// Get the first one. Convert it from CFDictionaryRef to NSDictionary.
NSDictionary *address = (NSDictionary *)CFBridgingRelease(ABMultiValueCopyValueAtIndex(addresses, 0));
@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