Skip to content

**SwiftyAs** is an Objective-C kinda way to do `as?` casting like in Swift.

License

Notifications You must be signed in to change notification settings

Inferis/SwiftyAs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftyAs

License  Version  Platform  Build Status

SwiftyAs is an Objective-C kinda way to do as? casting like in Swift.

The gist

In Swift, you can do:

let source: AnyObject = NSDictionary()

let array: source as? NSArray
// array = nil
let dict: source as? NSDictionary
// dict = source

With SwiftyAs you can do the same in Objective-C:

NSObject *source = [NSDictionary new];

NSArray* array = source.as(NSArray);
// array = nil
NSDictionary* dict = source.as(NSDictionary);
// dict = source

And that's about it. You can do the same with a isKindOfClass: check, of course, because that's what this just is. It's only wrapped a little nicer.

License

SwiftyAs is published under the MIT License.

See LICENSE for the full license.

About

**SwiftyAs** is an Objective-C kinda way to do `as?` casting like in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published