Skip to content

Instantly share code, notes, and snippets.

View alfredcc's full-sized avatar
:octocat:
learning

race alfredcc

:octocat:
learning
View GitHub Profile
@iAviatorJose
iAviatorJose / RoundedSection.swift
Last active July 20, 2022 03:25
Create Rounded Sections in UITableView
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if (cell.respondsToSelector(Selector("tintColor"))){
if (tableView == self.tvUserDetails) {
let cornerRadius : CGFloat = 12.0
cell.backgroundColor = UIColor.clearColor()
let layer: CAShapeLayer = CAShapeLayer()
let pathRef:CGMutablePathRef = CGPathCreateMutable()
let bounds: CGRect = CGRectInset(cell.bounds, 5, 0)
var addLine: Bool = false
@VincentSit
VincentSit / update_gfwlist.sh
Last active June 11, 2026 10:33
Automatically update the PAC for ShadowsocksX. Only tested on OS X. (Deprecated)
#!/bin/bash
# update_gfwlist.sh
# Author : VincentSit
# Copyright (c) http://xuexuefeng.com
#
# Example usage
#
# ./whatever-you-name-this.sh
#
# Task Scheduling (Optional)
@benjaminsnorris
benjaminsnorris / CollectionViewController.swift
Created March 10, 2016 03:00
Snap to center collection view cell
class CollectionViewController: UIViewController {
...
func snapToCenter() {
let centerPoint = view.convertPoint(view.center, toView: collectionView)
guard let centerIndexPath = collectionView.indexPathForItemAtPoint(centerPoint)
collectionView.scrollToItemAtIndexPath(centerIndexPath, atScrollPosition: .CenteredHorizontally, animated: true)
}
...
}
@Sadmansamee
Sadmansamee / StringExtensionHTML.swift
Created February 5, 2016 08:45
Decoding HTML Entities in Swift
//
// Extension.swift
// Hadith
//
// Created by Sadman samee on 2/5/16.
// Copyright © 2016 LoopsLab. All rights reserved.
//
import Foundation
import Foundation

Yep API Reference

概述

  • 基于 HTTP
  • RESTful
  • 采用标准 HTTP Code 返回错误
  • 返回格式为 JSON
@gonzalezreal
gonzalezreal / ios-cell-registration-swift.md
Last active March 5, 2025 02:07
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
@natecook1000
natecook1000 / nshipster-new-years-2016.md
Last active July 10, 2018 19:24
NSHipster New Year's 2016

Greetings and salutations, NSHipsters!

As the year winds down, it's a tradition here at NSHipster to ask you, dear readers, to offer up your favorite tricks and tips from the past year as gifts to your fellow hipsters. With iOS 9, El Capitan, brand new watch- and tvOS's, and the open-sourcing of some minor Apple-related tech, there's bound to be lots to share.

Submit your favorite piece of Swift or @objc trivia, helpful hints, unexpected discoveries, useful workarounds, useless fascinations, or anything else you found cool this year. Just comment below!

If you need inspiration, try [the list from last year][2015], or [from the year before][2014], or [from the year before that][2013].

@jspahrsummers
jspahrsummers / GHRunLoopWatchdog.h
Created January 28, 2015 20:50
A class for logging excessive blocking on the main thread
/// Observes a run loop to detect any stalling or blocking that occurs.
///
/// This class is thread-safe.
@interface GHRunLoopWatchdog : NSObject
/// Initializes the receiver to watch the specified run loop, using a default
/// stalling threshold.
- (id)initWithRunLoop:(CFRunLoopRef)runLoop;
/// Initializes the receiver to detect when the specified run loop blocks for
@s-aska
s-aska / Keychain.swift
Last active April 30, 2026 00:14
Swift Keychain class ( supported Xcode 6.0.1 )
import UIKit
import Security
class Keychain {
class func save(key: String, data: NSData) -> Bool {
let query = [
kSecClass as String : kSecClassGenericPassword as String,
kSecAttrAccount as String : key,
kSecValueData as String : data ]
@xtreme-daniel-crampton
xtreme-daniel-crampton / NSString+AdjustedSize.m
Created March 25, 2014 21:40
Returns a CGSize for a multi-line string.
- (CGSize)adjustedSizeWithFont:(UIFont *)font fromDefaultSize:(CGSize)defaultSize {
CGFloat additionalHeight = 0.0f;
NSDictionary *attributes = @{NSFontAttributeName : font};
CGRect rect = [self boundingRectWithSize:CGSizeMake(defaultSize.width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:attributes
context:nil];