How to import Objective-C framework in Swift framework

In a normal swift project we would create a bridging-header and import our objective-C framework in the bridging-header.

In the case of a framework you will need to create a custom swift module.

Let’s say you have an objective-C framework called MyFramework.

Firstly, add your framework to the project:

Then you need to add an aggregate to the project and target list.

Enter the name of the objective-c framework as the product name.

Then go to Build Phases > + > New Run Script Phase.

Enter the following script:

Make sure you set path of the header file to the path the header file of your objective-C framework. You can find the here: https://github.com/AnumQ/public_scripts/blob/master/module.sh

BUILD the aggregate MobileFramework by selecting it from the list of schemes.

Now we must include the framework in our project. We do this by adding the MobileFramework module to the Target Dependencies of our main project (framework).

Now build your MyCustomFramework project.

Simply use the the framework in your swift file by adding the import statement:

Vola!

Resign an IPA file including frameworks

Run these commands from the terminal in the folder where you have YOUR_IPA.ipa file.

  1. unzip -q YOUR_IPA.ipa
  2. rm -rf Payload/YOUR_IPA.app/_CodeSignature
  3. rm -rf Payload/YOUR_IPA.app/Frameworks/X.framework/_CodeSignature
  4. codesign -f -s “iPhone Distribution: XXX (XXXX)” Payload/YOUR_IPA.app/Frameworks/X.framework
  5. security cms -D -i PRODUCTION.mobileprovision > pr.plist
  6. /usr/libexec/PlistBuddy -x -c ‘Print :Entitlements’ pr.plist > YOUR_Plist.plist
  7. codesign -f -s “iPhone Distribution: XXX (XXXX)” –entitlements YOUR_Plist.plist Payload/YOUR_IPA.app
  8. zip -qr ResignedApp.ipa Payload SwiftSupport Symbols

Safe area fix guide for earlier versions of iOS

Safe area layout is introduced in iOS11 but what can we do if we are supporting < iOS 11 and we have a xib view that is initiated in a ViewController and somehow the upper part of the xib view appears behind the NavigationBar??? To fix this, simply add this line in your viewDidLoad.

self.edgesForExtendedLayout = UIRectEdge.init(rawValue: 0)

For more information visit EdgesForExtendedLayout at Apple.

Embed a UIViewController in a UINavigationController Programmatically

We know how to embed a ViewController in a NavigationController in Storyboard. However, I came across a scenario where I had to initiate it programmatically. The code:

let viewController = MyViewController()
let nav = UINavigationController(rootViewController: viewController)
self.navigationController?.present(nav, animated: true, completion: nil)

Create a script using Mac terminal

Scripts save us a lot of time. While scripts are running and doing the work we would have had to do manually, we can drink coffee or talk or just chill! 😃 Here is how you can create a simple script in mac terminal.

Run the following in the terminal:

Paste the following or your own private script:

echo "Hello, world!"

Hit

Ctrl + wq

Run the following:

sudo chmod 700 myScript.sh

Run the script by:

./myScript.sh

My personal scripts run a bunch of git commands all in one script or build an app with different configurations etc. I also have scripts that compile and build an application or more 😉

Happy scripting guys and girls!