An alternative to the #warning(…) tag in Xcode

Experienced old Objective-C developers like myself appreciated the #warning(...) tag in source code. It was a great way to remind yourself of things that might otherwise get lost in TODO comments that you forget to search for or your colleague is unaware of. Then it went away in Swift, and people like this guy came up with his own solution, which I liked for a while because it was truly customizable by keyword. Then Apple put #warning(...) back and that became less of an important thing to use.

…. Until I started working on Source Code that is to become a Cocoapod. For if you try to run pod lint spec MySpec.podspec, and there are compiler warnings, the validation process will fail.

So, return of the Run Script that goes through your Swift files and searches for keywords and adds warnings or errors as appropriate.

You can see the original post, or just create a run script (I think before you compile sources but I don’t think it matters), and add this (modify keywords as you like):

find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/"


Recipe: a Podfile with different Pods per target

So, say you want to have specific pods for unit testing. You wouldn’t want to include those in your main target, now would you?? Of course not! So, here’s a quick recipe so you can see how you would set that up in your Podfile.

Also assuming you checked the box ‘Include Unit Tests’ when you set up your Xcode project. Otherwise, see here

If the name of your app Target is MyGreatApp and your unit testing target is: MyGreatAppTests

platform :ios, "5.0"  #or whichever you need to support.  Your deployment target

pod "DCIntrospect"  # most awesome tool
pod "AFNetworking", "~>1.3.2"  # a standard lib iOS apps
pod "SSZipArchive"  # zipping/unzipping anyone?
pod "MD5Digest"   # don't let your filepaths be corrupted by newlines and spaces again.  
pod "MGImageUtilities"  #don't cache images for UIImageViews with fixed frames using a UIViewContentModeScaleAspectFi... resize and cache those

target :test, :exclusive => true do
    link_with 'MyGreatAppTests' #i.e. the test target name in your project
    pod 'OCMock', '~> 2.1.1'  #OCMock.  Great helper
    pod 'Expecta', '~> 0.2.1'  #nice syntax.  you can write readable pass conditions.