Created
July 7, 2014 09:25
-
-
Save jpsim/13971c81445219db1c63 to your computer and use it in GitHub Desktop.
SourceKit Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// JAZMusician.h | |
// JazzyApp | |
// | |
#import <Foundation/Foundation.h> | |
/** | |
JAZMusician models, you guessed it... Jazz Musicians! | |
From Ellington to Marsalis, this class has you covered. | |
*/ | |
@interface JAZMusician : NSObject | |
/** | |
The name of the musician. i.e. "John Coltrane" | |
*/ | |
@property (nonatomic, readonly) NSString *name; | |
/** | |
The year the musician was born. i.e. 1926 | |
*/ | |
@property (nonatomic, readonly) NSUInteger birthyear; | |
/** | |
Initialize a JAZMusician. | |
Don't forget to have a name and a birthyear. | |
@warning Jazz can be addicting. | |
Please be careful out there. | |
@param name The name of the musician. | |
@param birthyear The year the musician was born. | |
@return An initialized JAZMusician instance. | |
*/ | |
- (instancetype)initWithName:(NSString *)name birthyear:(NSUInteger)birthyear; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// JAZMusician.m | |
// JazzyApp | |
// | |
#import "JAZMusician.h" | |
@implementation JAZMusician | |
- (instancetype)initWithName:(NSString *)name birthyear:(NSUInteger)birthyear { | |
self = [super init]; | |
if (self) { | |
_name = [name copy]; | |
_birthyear = birthyear; | |
} | |
return self; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Musician.swift | |
// JazzyApp | |
// | |
/** | |
Musician models jazz musicians. | |
From Ellington to Marsalis, this class has you covered. | |
*/ | |
class Musician { | |
/** | |
The name of the musician. i.e. "John Coltrane" | |
*/ | |
var name: String | |
/** | |
The year the musician was born. i.e. 1926 | |
*/ | |
var birthyear: UInt | |
/** | |
Initialize a Musician. | |
Don't forget to have a name and a birthyear. | |
@warning Jazz can be addicting. | |
Please be careful out there. | |
@param name The name of the musician. | |
@param birthyear The year the musician was born. | |
@return An initialized Musician instance. | |
*/ | |
init(name: String, birthyear: UInt) { | |
self.name = name | |
self.birthyear = birthyear | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Usage: ./sourcekit_playground.sh ObjCHeader.h SwiftFile.swift | |
# Comment out what you're not testing | |
# Input arguments | |
objc_header_file=$1 | |
swift_file=$2 | |
# Generate temporary files | |
module_name='TempModule' | |
module_file='module.modulemap' | |
echo "module $module_name { header \"$objc_header_file\" }" > $module_file | |
#################### | |
# miscellaneous | |
#################### | |
#### | |
# Displays symbol table in swift binary | |
#### | |
# nm `xcrun -f swift` | |
#### | |
# Prints the expanded demangled format of the input mangled Swift symbol string | |
#### | |
# xcrun swift-demangle -expand _TtC11lldb_expr_012MySwiftClass | |
#################### | |
# swift | |
#################### | |
#### | |
# Prints a structured version of the AST to stderr | |
# Slower, more complete than dump-parse | |
# This output is still difficult to parse | |
#### | |
# xcrun swift -dump-ast $swift_file | |
#### | |
# Prints a structured version of the parsed source to stderr | |
# Faster, less complete than dump-ast | |
# This output is still difficult to parse | |
#### | |
# xcrun swift -dump-parse $swift_file | |
#### | |
# Generates .swiftdoc and .swiftmodule files from input | |
#### | |
# xcrun swift -emit-module $swift_file | |
#### | |
# Compiles the swift file | |
#### | |
# xcrun swift $swift_file | |
#################### | |
# sourcekitd-test | |
#################### | |
#### | |
# Prints a JSON array of the Swift file's syntax map | |
# followed by a JSON array of the Swift file's parsed tokens | |
# JSON strings aren't quoted | |
#### | |
# xcrun sourcekitd-test -req doc-info $swift_file | |
#### | |
# Prints the Swift interface of a module (Objective-C or Swift) | |
# strips out the comments | |
# followed by a JSON array of the syntax map | |
# followed by a JSON array of the parsed tokens | |
# JSON strings aren't quoted | |
#### | |
# xcrun sourcekitd-test -req doc-info -module $module_name -- -I `pwd` -sdk `xcrun --show-sdk-path` | |
#### | |
# Prints the Swift interface of an Objective C module | |
# preserves comments | |
# followed by a JSON array of the syntax map | |
# followed by a JSON array of the parsed tokens | |
# JSON strings aren't quoted | |
#### | |
# xcrun sourcekitd-test -req interface-gen -module $module_name -- -I `pwd` -sdk `xcrun --show-sdk-path` | |
#### | |
# Indexes a Swift file | |
#### | |
# xcrun sourcekitd-test -req index $swift_file -- `pwd`/$swift_file | |
#### | |
# Prints a JSON array of the Swift file's syntax map | |
#### | |
# xcrun sourcekitd-test -req syntax-map $swift_file | |
#################### | |
# swift-ide-test | |
#################### | |
#### | |
# Prints expanded usage instructions | |
#### | |
# xcrun swift-ide-test -help-hidden | |
#### | |
# Work in progress: will allow printing a JSON array of possible code completion options | |
# code-completion-token not defined | |
#### | |
# xcrun swift-ide-test -code-completion -code-completion-token=unkown -source-filename $swift_file | |
#### | |
# Parses and prints swiftdoc file generated by `swift -emit-module` | |
#### | |
# xcrun swift -emit-module $swift_file | |
# xcrun swift-ide-test -parse-rest -source-filename $swift_file"doc" | |
#### | |
# Prints Swift file without any comments | |
#### | |
# xcrun swift-ide-test -print-ast-typechecked -source-filename $swift_file | |
#### | |
# Prints Swift file without any comments and without typechecking | |
#### | |
# xcrun swift-ide-test -print-ast-not-typechecked -source-filename $swift_file | |
#### | |
# Prints parsed comments from the input Swift file: | |
# RawComment, BriefComment and FullCommentAsXML | |
#### | |
# xcrun swift-ide-test -print-comments -source-filename $swift_file | |
#### | |
# Prints USRs from the input Swift file | |
#### | |
# xcrun swift-ide-test -print-usrs -source-filename $swift_file | |
#### | |
# Prints a human-readable AST structure | |
#### | |
# xcrun swift-ide-test -structure -source-filename $swift_file | |
#### | |
# Prints HTML-style tags around tokens for syntax coloring: | |
# <kw>, <comment-block>, <type>, etc. | |
#### | |
# xcrun swift-ide-test -syntax-coloring -source-filename $swift_file | |
#### | |
# Prints Swift file with syntax coloring applied using terminal escape codes | |
#### | |
# xcrun swift-ide-test -syntax-coloring -terminal -source-filename $swift_file | |
#### | |
# Prints Swift interface of a module (Objective-C or Swift) | |
#### | |
# xcrun swift-ide-test -print-module -source-filename /dev/null -print-regular-comments -module-to-print Swift | |
# xcrun swift-ide-test -print-module -source-filename /dev/null -print-regular-comments -module-to-print Foundation | |
# xcrun swift-ide-test -print-module -source-filename /dev/null -print-regular-comments -module-to-print Foundation.NSArray | |
# Remove temporary files | |
rm $module_file | |
rm $swift_file"doc" $swift_file"module" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I believe this is all superseded now by https://github.com/jpsim/SourceKitten