- Author: Kgen (kgen@catch.la)
- 基于 HTTP
- RESTful
- 采用标准 HTTP Code 返回错误
- 返回格式为 JSON
| 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 | |
| #!/bin/bash | |
| # update_gfwlist.sh | |
| # Author : VincentSit | |
| # Copyright (c) http://xuexuefeng.com | |
| # | |
| # Example usage | |
| # | |
| # ./whatever-you-name-this.sh | |
| # | |
| # Task Scheduling (Optional) |
| 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) | |
| } | |
| ... | |
| } | |
| // | |
| // Extension.swift | |
| // Hadith | |
| // | |
| // Created by Sadman samee on 2/5/16. | |
| // Copyright © 2016 LoopsLab. All rights reserved. | |
| // | |
| import Foundation | |
| import Foundation |
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)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].
| /// 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 |
| 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 ] |
| - (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]; |