Introducing Nest - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
wezzard
V2EX    iDev

Introducing Nest

  •  
  •   wezzard 2015-06-08 01:26:22 +08:00 1912 次点击
    这是一个创建于 3858 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Github 地址

    Nest is a library which makes Foundation and Swift works more seamlessly and offers some great missing helpers, utilities in Foundation.

    How to Get Started

    Install via Cocoa Pods

    • pod "Nest.swift"
    • Add import Nest to your Swift source file

    Manually Install

    • Download or clone the project
    • Drag Nest’s Xcode project file to your workspace
    • Add Nest to your Emebed Binaries field in your target’s general page if you are building an app. Or add Nest to your Linked Frameworks and Libraries field in your target’s general page if you are building a framework.
    • Add import Nest to your Swift source file
    • You may need to add dependancies manually in the same way to your project file.
    • Enjoy your journey of Nest

    Contents

    NSProtocolInterceptor

    Circumstance:

    This class comes out of an answer I wrote on Stack Overflow: Intercept Objective-C delegate messages within a subclass. But as the original code was written in Objective-C and Swift's code-level-safety makes it become impossible that assign an object of any type to a pointer, I rewrote it in Swift and added some additional code to make it work in Swift now.

    Introduction:

    NSProtocolInterceptor is an object which masquerade itself as the protocol type(s) which you assigned at the initialization time, and intercepts message to the middle man if it could respond which originally intended to send to the receiver.

    Examples:

    Initialization

    • NSProtocolInterceptor(aProtocol: Protocol)

    • NSProtocolInterceptor(protocols: [Protocol])

    • NSProtocolInterceptor(protocols: Protocol ...)

    Intercept messages within a subclass

    • MyScrollView.swift
    class MyScrollView: UIScrollView, UIScrollViewDelegate { let delegateInterceptor: NSProtocolInterceptor func scrollViewDidScroll(scrollView: UIScrollView) { if self.delegate?.respondsToSelector("scrollViewDidScroll:") == true { self.delegate?.scrollViewDidScroll?(scrollView) } } required init(coder aDecoder: NSCoder) { delegateInterceptor = NSProtocolInterceptor(aProtocol: UIScrollViewDelegate.self) super.init(coder: aDecoder) delegateInterceptor.middleMan = self super.delegate = delegateInterceptor as? UIScrollViewDelegate } override init(frame: CGRect) { delegateInterceptor = NSProtocolInterceptor(aProtocol: UIScrollViewDelegate.self) super.init(frame: frame) delegateInterceptor.middleMan = self super.delegate = delegateInterceptor as? UIScrollViewDelegate } } 

    For UIKit bridging header claims UIScrollView's delegate property as unowned(unsafe) and doesn't mark UIScrollViewDelegate up as a class only protocol, we cannot override the delegate property in Swift for now. So let's override it in Objective-C.

    • MyScrollView+OverrideDelegate.h
    @import UIKit; #import "ProductModuleName-Swift.h" @interface MyScrollView (OverrideDelegate) @end 
    • MyScrollView+OverrideDelegate.m
    @import Nest; #import "MyScrollView+OverrideDelegate.h" @implementation MyScrollView (OverrideDelegate) - (id <UIScrollViewDelegate>)delegate { return (id <UIScrollViewDelegate>)self.delegateInterceptor.receiver; } - (void)setDelegate:(id <UIScrollViewDelegate>)delegate { super.delegate = nil; self.delegateInterceptor.receiver = delegate; super.delegate = (id <UIScrollViewDelegate>)self.delegateInterceptor; } @end 

    NSReuseCenter & NSReusable

    Circumstance:

    Reusing is an usual way to optimize a program's performance. This class it designed for making reusing simpler.

    Introduction:

    NSReuseCenter offers an enqueue and dequeue mechanism for objects conform to the NSReusable protocol.

    Examples:

    Initializations

    let theReuseCenter = NSReuseCenter<AParticularReusable>() 

    Enqueue an unused object

    theReuseCenter.enqueueUnused(anUnusedObject) 

    Dequeue a reusable object for a particular reuse identifier

    theReuseCenter.dequeueReusableWithReuseIdentifier(aReuseIdentifier) 

    Query all reusable objects for a particular reuse identifier

    theReuseCenter.reusableForReuseIdentifier(aReuseIdentifier) 

    Collection Functions

    Circumstance:

    There might be a situation you had encountered before where you wanted to find an NSObjectProtocol conformed object in a protocol-constrained collection and Swift didn't suppose your NSObjectProtocol conformed object implements the Equatable protocol which made you unable to use the find function in Swift standard library. These collection of functions assume that any NSObjectProtocol conformed object has a clear understand on isEqual: function and use that function to evaluate equality between objects.

    Functions:

    • Check an NSObjectProtocol conformed object is contained in a collection of NSObjectProtocol conformed objects.

      NSContains<C where C: CollectionType, C.Generator.Element: NSObjectProtocol>(domain: C, element: C.Generator.Element) -> Bool

    • Find the index of an NSObjectProtocol conformed object in a collection of NSObjectProtocol conformed objects.

      NSFind<C : CollectionType where C.Generator.Element: NSObjectProtocol>(domain: C, value: C.Generator.Element) -> C.Index?

    • Calculate intersected objects in two collections of NSObjectProtocol conformed objects.

      NSIntersected<C : ExtensibleCollectionType where C.Generator.Element : NSObjectProtocol>(collectionA: C, collectionB: C) -> C

    • Evaluate differences between two collections of NSObjectProtocol conformed objects.

      NSDiff<Seq: SequenceType where Seq.Generator.Element: NSObjectProtocol>(from fromSequence: Seq?, to toSequence: Seq?, differences: SequenceDifference, unchangedComparator: ((Seq.Generator.Element, Seq.Generator.Element)->Bool) = default, usingClosure changesHandler: (change: SequenceDifference, fromElement: (index: Int, element: Seq.Generator.Element)?, toElement: (index: Int, element: Seq.Generator.Element)?) -> Void)

    • Remove an NSObjectProtocol conformed object in a collection of NSObjectProtocol conformed objects.

      NSRemove<C : RangeReplaceableCollectionType where C.Generator.Element : NSObjectProtocol, C.Index: protocol<Comparable, BidirectionalIndexType>> (inout collection: C, elements: C) -> C

    Runtime Functions

    Functions:

    • Check if selector belongs to a protocol.

      sel_belongsToProtocol(aSelector: Selector, aProtocol: Protocol) -> Bool

    • Swizzle a selector with an implementation on a class. The original implementation would be connected with a selector which consists of the given prefix and its original selector.

      class_swizzleClass(aClass: AnyClass, selector: Selector, withImplementation: IMP, selectorPrefix: String) -> Bool

    Conformity of NSDate to Comparable

    Circumstance:

    I made NSDate conforms to Comparable to get avoid of comparing two NSDate objects by using its compare: function.

    Example:

    let now = NSDate() let tenSecondsBefore = now.dateByAddingTimeInterval(-10) if now > tenSecondsBefore { println("Now is later than ten seconds before") } 

    Search All Occurrence for Given String in NSString

    Circumstance:

    Search all occurrence for given string in an NSString without using regular expression.

    Example:

    Search string in the whole string with the current locale

    let aString = "This is a string" let aStringInNSString = aString as NSString let occurrences = aStringInNSString.rangesOfString("s", options: NSStringCompareOptions.CaseInsensitiveSearch, range: nil, locale: nil) 

    NSRangeMake

    Example:

    let anNSRange = NSRangeMake(location: 0, length: 10) 

    NSError Initialization Conveniences for Using CoreData

    Example:

    Combine two errors

    let anError = NSError(error: anError, anotherError: anOtherError) 

    Combine an error in a pointer with another error

    let anError = NSError(errorPointer:anErrorPointer, secondError: secondError) 

    Combine an array of errors

    let anError = NSError(errors: errors) 

    Dependancies

    Github 地址

    目前尚无回复
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1031 人在线   最高记录 6679     &nsp; Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 38ms UTC 18:26 PVG 02:26 LAX 10:26 JFK 13:26
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86