Code Snippets for Xcode
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
SnippetImporter
Xcode4CodeSnippets.xcworkspace
bin
.gitignore
ClearSnippets.command
ExportSnippets.command
FindNewSnippets.command
GitUpdate.command
ImportSnippets.command
LICENSE
README.md
snippets.sh
sst_animblock.codesnippet
sst_animfullblock.codesnippet
sst_animspringblock.codesnippet
sst_appearance_spelunk_block.codesnippet
sst_assert_main_thread.codesnippet
sst_block_inline.codesnippet
sst_block_named_variable.codesnippet
sst_block_peform_after_delay.codesnippet
sst_blockmethod.codesnippet
sst_blocknoparamsmethod.codesnippet
sst_class_extension.codesnippet
sst_collectionview_delegate.codesnippet
sst_constraints_fill.codesnippet
sst_date_is_after.codesnippet
sst_debuglog.codesnippet
sst_debuglog_method.codesnippet
sst_debuglogd.codesnippet
sst_define_gcd_run_on_main_queue.codesnippet
sst_define_macros.codesnippet
sst_define_singleton_macro.codesnippet
sst_deprecated.codesnippet
sst_directory_exists.codesnippet
sst_dl.codesnippet
sst_dl_error.codesnippet
sst_dl_object.codesnippet
sst_document_delete.codesnippet
sst_draw_image_method.codesnippet
sst_draw_image_with_block.codesnippet
sst_error_create.codesnippet
sst_file_exists.codesnippet
sst_fmtdatetime.codesnippet
sst_gcd_async_wait.codesnippet
sst_gcd_asyncqueue.codesnippet
sst_gcd_default_priority_queue.codesnippet
sst_gcd_dispatchafter.codesnippet
sst_gcd_getqueuelabel.codesnippet
sst_gcd_high_priority_queue.codesnippet
sst_gcd_low_priority_queue.codesnippet
sst_gcd_main_queue.codesnippet
sst_gcd_wait_for_blocks.codesnippet
sst_height_for_vc_view.codesnippet
sst_height_main_screen.codesnippet
sst_image_resize_to_max.codesnippet
sst_inline_block_variable.codesnippet
sst_is_ios7_or_later.codesnippet
sst_isviewcontrollervisible.codesnippet
sst_localized_string.codesnippet
sst_log.codesnippet
sst_log_fonts.codesnippet
sst_log_mode.codesnippet
sst_maassert.codesnippet
sst_maassert_defined.codesnippet
sst_method.codesnippet
sst_notification_block_observer_property.codesnippet
sst_notification_handler.codesnippet
sst_notification_named_block.codesnippet
sst_notification_observe.codesnippet
sst_notification_observer_property.codesnippet
sst_notification_observewithblock.codesnippet
sst_notification_post.codesnippet
sst_notification_post_with_userinfo.codesnippet
sst_notification_remove.codesnippet
sst_notification_remove_block_observer.codesnippet
sst_nsassert.codesnippet
sst_nsassert_blocks.codesnippet
sst_pragma_unused.codesnippet
sst_prepareforsegue.codesnippet
sst_prop.codesnippet
sst_run_on_main_thread.codesnippet
sst_section_header.codesnippet
sst_string_constant_header.codesnippet
sst_string_constant_implementation.codesnippet
sst_string_contains.codesnippet
sst_string_height_attributed.codesnippet
sst_string_height_regular.codesnippet
sst_string_starts_with.codesnippet
sst_strong_self.codesnippet
sst_suppress_deprecation_warnings.codesnippet
sst_tableview_delegates.codesnippet
sst_udid_create.codesnippet
sst_unwind_segue.codesnippet
sst_viewdidappear.codesnippet
sst_viewdiddisappear.codesnippet
sst_viewdidload.codesnippet
sst_viewwillappear.codesnippet
sst_viewwilldissappear.codesnippet
sst_weak_self.codesnippet

README.md

Xcode Code Snippets

I've created or collected the following code snippets to speed up my work. My snippets focus on a few areas.

  • animation
  • blocks
  • async (GCD and queues)
  • notifications
  • debugging
  • formatting

To use the snippets you will want to place them in the following folder.

~/Library/Developer/Xcode/UserData/CodeSnippets

There is an import and export script which can be used to handle putting these files in place.

You will need to restart Xcode to see the change.

I am open to feedback on improving this code or adding more code snippets which would compliment them.

Filename Prefix

The filenames have a prefix of SST for SmallSharpTools, which is my company. This is done to make it easier to use these snippets alongside other snippets you may want to use either that you created or another GitHub repo. A script named GitUpdate.command is included which will pull the latest from GitHub and copy the code snippets in place. If you were to automate this script you could automatically stay current with these snippets. Updates are made periodically to add new snippets or to adjust snippets due to a bug or changes to iOS/Mac APIs.

Snippet Importer

Managing snippets has been a bit of a manual process. When a new snippet is created with Xcode a new file is added to the working folder with a long name which is not descriptive. The name which is used to name each file within this collection includes the collection prefix, the snippet completion prefix and the file extension. Renaming the automatic names to use this convention was a bit of copy/paste work which has not been eliminated with the Snippet Importer project which builds a command-line utility which is used to copy new files from the working folder to the managed Git folder with a filename using the naming convention and then copied to the working folder again where Xcode will pick it up the next time it is relaunched. This command-line utility takes 3 parameters and also has the help switch (-?) like most utilities. The script snippets.sh uses it in the import option to import newly created snippets to the managed Git folder where the changes can be added and committed to the repository.

This project and the new importer script are built to help with anyone manage their collection with their own prefix.

Caveat

I found that copying a snippet to create a modified version without changing the Guid value causes Xcode to crash. I expect a conflicting keyword would also be a problem. The import/export process to sync snippet collections should handle these details to ensure different files do not cause conflicts. This would likely require a command-line utility or a more advanced shell script.

License

Xcode Code Snippets are available under the MIT license. See the LICENSE file for more info.

Contact

Brennan Stehling
SmallSharpTools
@smallsharptools (Twitter)