Skip to content

Instantly share code, notes, and snippets.

View LBUrlUtilities.m
/// 获取 url 的顶级域名. 比如, a.example.com 的顶级域名是 example.com
- (NSString *)topLevelDomainNameFromUrl:(NSURL *)url {
if (url.absoluteString.length == 0) {
return nil;
}
NSString *topLevelDomainName = @"";
NSString *host = url.host;
NSArray *subStrings = [host componentsSeparatedByString:@"."];
NSUInteger count = subStrings.count;
@Huang-Libo
Huang-Libo / ColorUtils.m
Last active Sep 27, 2019
Objective-C 中的颜色工具
View ColorUtils.m
/// 参考 WeexSDK `WXConvert.m` 中的 `+UIColor:` 方法 (且在其基础上添加了对 #rrggbbaa 格式的支持)
/// @param colorString 颜色字符串, 支持以下格式:
/// #fff
/// #rrggbb
/// #rrggbbaa
/// rgb(r,g,b)
/// rgba(r,g,b,a)
+ (UIColor *)colorWithColorString:(NSString *)colorString {
// 1. check cache
static NSCache *colorCache;
@Huang-Libo
Huang-Libo / singleton.m
Last active Sep 7, 2017
Objective-C singleton
View singleton.m
// `dispatch_once' singleton initialisation
+ (id)sharedInstance {
static EOCClass *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
@Huang-Libo
Huang-Libo / gist:20317c86eecde6e492311c0b6adb7803
Created Jun 16, 2017 — forked from snikch/gist:3661188
Find the current top view controller for your iOS application
View gist:20317c86eecde6e492311c0b6adb7803
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
View YTKAnimatingRequestAccessory.h
//
// YTKAnimatingRequestAccessory.h
// Ape_uni
//
// Created by Chenyu Lan on 10/30/14.
// Copyright (c) 2014 Fenbi. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <YTKBaseRequest.h>