Skip to content

Instantly share code, notes, and snippets.

View chiahsien's full-sized avatar

Nelson chiahsien

View GitHub Profile
//
// Reference:
// https://khanlou.com/2016/07/implementing-dictionary-in-swift/
//
import Foundation
class Item<Key: Hashable, Value> {
let key: Key
var value: Value
@chiahsien
chiahsien / API.m
Created October 1, 2014 04:18
AFNetworking-RACExtensions example
- (RACSignal *)fetchSomething {
NSString *path = @"path/to/endpoint";
@weakify(self);
RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id < RACSubscriber > subscriber) {
@strongify(self);
[[self rac_GET:path parameters:nil] subscribeNext:^(id responseObject) {
NSError *error = nil;
NSArray *results = [MTLJSONAdapter modelsOfClass:[XXXModel class] fromJSONArray:responseObject error:&error];
if (error) {
//
// UIDeviceHardware.h
//
// Used to determine EXACT version of device software is running on.
#import <Foundation/Foundation.h>
@interface UIDeviceHardware : NSObject
- (NSString *) platform;
@chiahsien
chiahsien / uncrustify.cfg
Last active May 6, 2016 08:08
My Uncrustify config for Objective-C
#
# Uncrustify Configuration File
# File Created With UncrustifyX 0.4.3 (252)
#
# Alignment
# ---------
## Alignment
@chiahsien
chiahsien / gist:7867588
Last active December 30, 2015 18:29
取得字體顯示名稱
#import <CoreText/CoreText.h> // Don't forget to import CoreText
NSArray *familyNames = [UIFont familyNames];
for (NSString *familyName in familyNames) {
NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
for (NSString *fontName in fontNames) {
CTFontRef fontRef = CTFontCreateWithName((__bridge CFStringRef)(fontName), 16, NULL);
NSString *displayName = CFBridgingRelease(CTFontCopyDisplayName(fontRef)); // Here's the magic...
NSLog(@"%@", displayName);
}
@chiahsien
chiahsien / .gitignore
Created December 20, 2012 05:47
My .gitignore
#===============#
# For Windows
#===============#
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
@chiahsien
chiahsien / Sublime Text 3 Settings.json
Last active October 13, 2015 21:08
My Sublime Text 3 Configuration
{
"bold_folder_labels": true,
"ensure_newline_at_eof_on_save": true,
"fade_fold_buttons": true,
"file_exclude_patterns":
[
".DS_Store",
".gitkeep",
"dump.rdb"
],
@chiahsien
chiahsien / gist:3980627
Created October 30, 2012 14:46
UITableView 滾到底時載入更多
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// 或許你會有一個變數來判斷目前是否正在載入資料
if (isLoading)
return;
// 判斷滾到哪裡的時候要自動載入更多,這可以依需求調整
if ((scrollView.contentOffset.y > scrollView.contentSize.height - scrollView.frame.size.height * 2) &&
// 或許你會有其他辦法來判斷是否還有更多資料可以載入
(currentPage < pageCount))
@chiahsien
chiahsien / PlayGameViewController.m
Created October 25, 2012 09:23
Singleton 使用範例
// 在玩遊戲的 View Controller
#import "PlayGameViewController.h"
#import "ScoreManager.h"
// 遊戲結束了,有個方法專門用來處理後續動作
- (void)gameOver
{
// 1. 取得 score manager
ScoreManager *scoreManager = [ScoreManager sharedInstance];
@chiahsien
chiahsien / gist:3937898
Created October 23, 2012 09:35
手動載入 Storyboard
- (IBAction)click:(id)sender
{
// 1. 載入特定的 Storyboard
UIStoryboard *board = [UIStoryboard storyboardWithName:@"SecondStoryboard" bundle:nil];
// 2. 初始化這個 storyboard 裡的某一個 view controller
MyCustomViewController *vc = [board instantiateViewControllerWithIdentifier:@"My Custom View Controller"];
// 3. 顯示這個 view controller
[self presentModalViewController:vc animated:NO];
}