Here's an Xcode user script which should not wipe out new lines in the text.
#!/usr/bin/python
#
# Wraps selection in braces.
# Set Input to "Selection".
# Set Output to "Replace Selection".
tabChar = '\t' # Replace with spaces if desired
input = '''%%%{PBXSelectedText}%%%'''
print "{"
for line in input.splitlines():
print tabChar + line
print "}"
See the Script Input Variables section of the Xcode Workspace Guide for more information on %%%{PBXSelectedText}%%%
and the other available input variables.
EDIT: added support for indenting the code to be surrounded by a given amount. Right now the indent must be hard coded. It may be possible to get this value from, e.g., the Xcode preferences file, but I didn't go that far.