Skip to content

Instantly share code, notes, and snippets.

//
// TCHorizontalSelectorView.m
// TwinCodersLibrary
//
// Created by Guillermo Gutiérrez on 16/01/13.
// Copyright (c) 2013 TwinCoders S.L. All rights reserved.
//
#import <UIKit/UIKit.h>
@kingiol
kingiol / NSString.m
Created January 13, 2014 10:04 — forked from 0xced/NSString.m
/*
* Most NSString instances will actually be __NSCFString instances, so here are both NSString and __NSCFString implementations.
* If you know how to create an NSString instance whose class is actually NSString please let me know.
* Other possible concrete subclasses of NSString are: NSConstantString, __NSCFConstantString, NSPathStore2, NSSimpleCString and __NSLocalizedString.
*/
// CoreFoundation.framework 635.19.0 (Mac OS X 10.7.3)
@implementation NSObject
- (BOOL) isNSString__
#import <UIKit/UIKit.h>
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/MobileCoreServices.h>
static UIImage *frameImage(CGSize size, CGFloat radians) {
UIGraphicsBeginImageContextWithOptions(size, YES, 1); {
[[UIColor whiteColor] setFill];
UIRectFill(CGRectInfinite);
CGContextRef gc = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(gc, size.width / 2, size.height / 2);
@implementation NSString (Range)
- (NSArray *)rangesOfString:(NSString *)substring {
if (self.length == 0 || substring.length == 0)
return @[];
NSRange searchRange = NSMakeRange(0, self.length - 1);
NSMutableArray *ranges = [@[] mutableCopy];
while (searchRange.location < self.length) {
@kingiol
kingiol / UIDevice+Orientation
Created November 10, 2015 09:51
监听手机当前的方向
UIDevice *device = [UIDevice currentDevice]; //Get the device object
[device beginGeneratingDeviceOrientationNotifications]; //Tell it to start monitoring the accelerometer for orientation
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; //Get the notification centre for the app
[nc addObserver:self //Add yourself as an observer
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:device];
@kingiol
kingiol / UIKeyboard
Created November 10, 2015 11:27
iOS键盘事件
【iOS中有关键盘事件】
let notificationCenter = NSNotificationCenter.defaultCenter()
notificationCenter.addObserver(self, selector: "adjustForKeyboard:", name: UIKeyboardWillHideNotification, object: nil)
notificationCenter.addObserver(self, selector: "adjustForKeyboard:", name: UIKeyboardWillChangeFrameNotification, object: nil)
func adjustForKeyboard(notification: NSNotification) {
let userInfo = notification.userInfo!
//
// ViewController.m
// AVPlayerCaching
//
// Created by Anurag Mishra on 5/19/14.
// Sample code to demonstrate how to cache a remote audio file while streaming it with AVPlayer
//
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@kingiol
kingiol / gist:40edb046ca3c7aec4d3652641a9338ce
Created August 11, 2018 14:02
打印UIView的所有子节点结构
func hierarchyOfView(_ view: UIView, level: Int = 1) {
let subviews = view.subviews
if subviews.isEmpty { return }
for subview in subviews {
var blank = ""
for _ in 1..<level {
blank += "-"
}
@kingiol
kingiol / Storage.swift
Created August 12, 2018 11:44 — forked from saoudrizwan/Storage.swift
Helper class to easily store and retrieve Codable structs from/to disk. https://medium.com/@sdrzn/swift-4-codable-lets-make-things-even-easier-c793b6cf29e1
import Foundation
public class Storage {
fileprivate init() { }
enum Directory {
// Only documents and other data that is user-generated, or that cannot otherwise be recreated by your application, should be stored in the <Application_Home>/Documents directory and will be automatically backed up by iCloud.
case documents
@kingiol
kingiol / gist:09e8b30e45d5d30d4dc70ecedcdf997c
Last active September 1, 2018 15:14
Can print any object to String
infix operator ???: NilCoalescingPrecedence
public func ???<T>(optional: T?, defaultValue: @autoclosure () -> String) -> String {
switch optional {
case let value?:
return String(describing: value)
case nil:
return defaultValue()
}
}