Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS SDKs: Renaming a lot of classes

I'm developing an iOS SDK that integrates other SDKs (Facebook SDK 3.5, for example). To prevent collisions and allow my customers to import those SDKs as well, I want to rename all of the classes/enums in my code (for example, rename FBSession to RDFBSession, etc).

Is there an easy way to do this instead of going class-by-class and using Xcode's rename feature?

like image 863
Ran Dahan Avatar asked May 20 '13 08:05

Ran Dahan


2 Answers

Apple provide a command-line tool called tops(1) that is designed for scripting large-scale code refactoring (renaming C functions, Objective-C methods, classes, and other tokens):

 tops -verbose replace "FBSession" with "RDFBSession" Sources/*.[hm]

If you have a lot of replacements, you can put all of the replace... commands into a file that you pass with the -scriptfile option. The man page has more information on the more complex commands/options (and examples).

like image 102
一二三 Avatar answered Nov 14 '22 14:11

一二三


Xcode also offers textual Search and Replace. This will be faster than individual refactors, but it is ultimately less automated. You can make the step by step refactoring faster by first minimizing the project to the relevant dependencies/sources (if possible).

However, renaming the declarations in a library will not alter the symbol names of its associated binary. If it is distributed with a binary, then renaming will just result in linker errors or (in some cases) runtime errors.

The best idea if you need to use a 3rd party library which your clients might also use is to simply inform them they need to link the library with their app, then publish the version(s) the current release supports so they know they have some extra testing if they go too far ahead with some libraries.

like image 3
justin Avatar answered Nov 14 '22 13:11

justin