Skip to main content

Posts

Showing posts with the label Tips & Tricks

Successfully installing CocoaPods in M1 Macs

Installation steps of cocoapods in the new Macs with M1 chipset is little different than Intel based Macs. If we casually run `pod install`, we are likely to encounter error related to the ffi gem 🤨. Open the terminal and follow below steps to solve the error and install pod dependencies successfully. Step1 : At first, install ffi gem intel version > sudo arch -x86_64 gem install ffi Steps 2: Install cocoapod  > sudo gem install cocoapods Steps 3 (optional) : Go to project root folder and initialise pod file if not created already. > arch -x86_64 pod init Steps 4: Now Install pod dependencies. > arch -x86_64 pod install

Safari Technology Preview | Best way to debug WebPages in iPhone, iPad or Mac Apps.

I enjoyed using Web Inspector tool from Safari Developer options to debug active web pages in iPhone or iPad. For instance, WKWebView running on iPhone. With the update of MacOS Big Sur 11.4 it got broke !! The Safari (14.1.1) web inspector only limited to Sources, Console and Audit. Also this issue started floating in SO thread here . Last week I got rescued by a lesser known application (at lest in my team!) Safari Technology Preview from Apple. Safari Technology Preview app will give you full scale options includes the most recent version of WebKit, the rendering engine that powers Safari. It requires a Mac running macOS Mojave v10.14 or later. I highly recommend this Apple provided in-house Browser for Developer.

Reclaim the Xcode occupied space

  Open  Terminal  from Mac and run commands one by one.  > sudo rm -rf /.DocumentRevisions-V100/ > rm -rf ~/Library/Developer/Xcode/DerivedData > rm -rf ~/Library/Developer/Xcode/Archives  > rm -rf ~/Library/Developer/Xcode/iOS\ DeviceSupport > rm -rf ~/Library/Caches/com.apple.dt.Xcode > xcrun simctl delete unavailable What happens ?? 1. Removes the snapshot of opened documents.  2. Removes all derived data that generated from Xcode projects.  3. Removes the archived builds from all apps. 4 iOS device support files dropped. 5. Clear caches from Xcode. 6. Deletes unused & outdated iOS simulator versions. 

Pocket guide to iOS app development enthusiasts

I would like to share all possible channels & resources that helps to pitch in iOS development. I'm sure existing iOS ninjas who are already consuming those in one or other ways. Before listing my points - we all know it's most important to keep updated techs and trends. Many cases I have seen some of the channels & connections helped developers to get their new jobs or app contracts. 1. Apple's Official Developer guide. Apple Documentation  is the first go over for all references.  Swift.org for Swift Language starting point. WWDC Videos (& New app launched as well) 2. Social Media Groups - Fast & easy way to connect with iOS community. Facebook Group   Twitter Lists for iOS handles 3. Slack workspaces - A sweet hub of all iOS developers connected by channels. ios-developers.slack.com (Suggested) 4. Online Courses   - Gives opportunity to learn and be certified developers. Udemy AppBrewery  Alison ( and more ) 5...

♻️ Reusing Image with Template render mode in iOS

UIImage comes with property " renderingMode " from iOS 7 onwards. It can be set either 'alwaysTemplate' or 'alwaysOriginal'. This enum property helps us to re-use images that may thin your app size too. Let's get into to a real scenario ! I have added button as heart icon that gives like or dislike functionality for a picture. As you can see in the result below, heart image turns red when liked and stays gray when disliked. In such cases only one image asset can be used. Considering a UIButton object already created and added as a subview in the project, let's start with functionality. Again, I have only one image with name 'heart' in the asset folder (with gray fill). Using same image, I can create 2 instances of UIImage objects using rendering modes.     let notLikedImage = UIImage . init (named: "heart" )?. withRenderingMode (. alwaysOriginal )  let likedImage = UIImage . init (named: "heart" )?....

Prevent Navigationbar or Tabbar overlapping Subview - solved for Card view

Recently, I started with a Card view added as a subview of UIView in a view-controller. When a view controller created along subviews, it tends to use entire screen bounds and also slips behind Tab bar or Navigation bar. In my current situation, it's second case. Casually new iOS developers will write a patch by additional value for coordinate y and subtracting bar height from its size. A lot of them posted in SO threads too : How to prevent UINavigationBar from covering top of view? View got hidden below UINavigationBar iOS 7 Navigation Bar covers some part of view at Top So, how I got solved ? self.edgesForExtendedLayout = [] This  will avoid all subviews in a view controller get behind any bars. Read full apple  documentation on here. Full Source code below :  //Simple view controller where its view layed-out as a card. class WidgetCardViewController : UIViewController { var containerView = UIView () //MARK:- View Controller Life Cyc...

UICollectionViewCell shows with wrong size on First time - Solved

We commonly use Collection view where its cell size calculated run time. The flow layout delegate is responsible to return individual cell sizes. BUT in most of the cases, delegate method `collectionView: layout sizeForItem:` expects cell size too early. Before generating actual cell size. extension YourViewController : UICollectionViewDelegateFlowLayout { func collectionView ( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize (width: externalWidth, height: externalHeight) } } For instance, if a cell size depends on external view and its frame is not yet ready - results with wrong (or outdated) cell size. Typically happens for the first time view controller laid out all views. You can find similar queries in StackOverflow community : Collection view sizeForItemNotWorking UICollectionViewCell content wrong size on first load How to refresh UICollec...

Top 7 iOS developers you must follow on Twitter

Twitter is one of the quickest way to microblog that leverage specifically us (iOS Developers) to connect & share knowledge. Recently I had been consuming daily dose of content from these top 7 twitter accounts. Paul Hudson ( @twostaws ) Creator of Hacking with Swift  - who wrote couple of books on iOS, macOS, tvOS & watchOS. John Sundell ( @johnsundell ) Speaker, Creator of Swift by Sundell blog having tons of valuable tutorials and sessions on Swift  programming. Dave Verwer ( @daveverwer ) Author of iOS Dev weekly - a popular & long running weekly newsletter for app developer. Lisa Dziuba ( @lisadziuba ) She built a strong community around iOS development, mobile design and marketing called Flawless-iOS. Sean Allen ( @seanallen_dev ) An indie iOS developer & content creator who came from non-technical background. He owns a popular youtube channel on iOS development & vlog. Donny Wals ( @DonnyWals ) iOS developer at Disney Streaming ...

Quick 4 steps to get start with Test Flight for iOS

We can quickly distribute app to a specific set of beta testers over-the-air immediately with Test flight. In the below short note, I listed 4 simple steps to begin with Test Flight.  Step 1:    ’Test Flight’ app needs to be installed in the iPhone device & login to Apple account mail (Previously shared with Developer) in the same. App Store download link Step 2:  Whenever a developer publishes a new build (via iTunes connect panel), All testers will receive an invitation mail from Test Flight. Step 3:   After invitation accepted, Open the test flight app, install test build.  Example for step 2 & 3 ( Image Source : Appcoda) Step 4: Now we can start testing the app. In case any future app build updates, testers will receive notifications. That's all. Hope these steps will help new testers & promises a great quality app in the app store. 

Helpful XCode command tips

   Xcode bundled with iOS Simulators has got powerful tools and options. In few cases we need to go beyond those options - via terminal commands. In this article I listed couple of them & You can expect me to keep updating. To show gestures in simulator //Note: Restart simulator after executing command for immediate effect > defaults write com.apple.iphonesimulator ShowSingleTouches 1 To record video in the simulator //Note : Close simulator and run command > xcrun simctl io booted recordVideo ~/Desktop/record_file_name.mp4 Delete all unused simulators to free up mammoth Space > xcrun simctl delete unavailable Bonus : To show hidden files in the mac > defaults write com.apple.finder AppleShowAllFiles YES

Backing multiple iOS versions

A latest iOS version update can cover ~85% of iPhone users which is significant compared to a newly released Android running just ~0.1% of devices. ( @StatistaCharts collected on September 2018 - iOS 11 vs Android Pie). If your application matters for the rest ~15% of “genuine” iOS users, then you have to spend extra time to support. Why does it matters ? Giving uniform user experience irrespective of iOS version and device factors - will give bonus market space for the sales. Essentially it will boost your revenue and popularity of the application. Deployment Target vs Base SDK Before heading to solution, we have to understand Xcode settings for Deployment Target and Base SDK.  A deployment target refers to the oldest version of iOS that is capable of running your project. To change your deployment target, open up your project file in Xcode and check the setting under Build Settings -> Deployment. Base SDK refers to the newest version of iOS that is capable of runn...

5 Common pitfalls while starting iOS app

In this article I listed 5 most common missteps while starting iOS application. Typically beginners might have taken these approaches.  1. Internet connectivity status checking over response error : It is essential to check network connectivity status offline or online before starting services.  To test reachability you might wrote in response callback :  Problem : Time consuming in case URL takes tool long to respond. More over you cannot rely on server to check connectivity. Simply because server may be down at the moment you sent request. Solution : Use Apple’s Reachability class. It can monitor network status of WiFi or Cellular data instantly. Notifies in case network status changes. Bonus - Also make sure app works in iPv6 network as well. 2. Textfield behind keyboard :  Credit : Stackoverflow.com We start developing app in Xcode and run in Simulator. By default keyboard preference of simulator is hidden and we kept using Mac keybo...

Quickest way to test Apple Push Notification Service APNS

We got plenty of applications powered by Apple Push notification feature and even we know how it's implemented.  At the end when it comes for testing, simulator won’t help you out. We need actual hardware device. Since Xcode 7, you can now test apps on your device without a program membership. However, to configure push notifications you need a push notification certificate for your App ID, which requires the program membership. Now assume that your server is not ready to trigger notifications. Well, it doesn't stop you testing and see the magic working ! Listed below best options for the same. From online portals : http://apns-gcm.bryantan.info/ http://pushtry.com/ http://www.pushwatch.com/ From Mac app : https://itunes.apple.com/in/app/apn-tester-free/id626590577?mt=12 https://github.com/noodlewerk/NWPusher I have used NWPusher and I will recommend the same. ;-)  So, here its recipe  Key items  [1] PEM file [2] Device toke...

SVN configuration in MAC Android Studio

To setup svn and checkout repository in Android Studio 2.2.2 for Mac , we have to follow simple few steps .   Step 1: Go to Android Studio Preferences  >  Version Control > Subversions Select checkbox for command line client Now, type ` svn ` in the box. click on ' Apply ' and ' Save ' Step 2: From the top menu, VCS > Checkout from Version Control Paste SVN path in the under repository path after hitting ‘+’ button. Then you can see you repository listed for checkout.   If you expand the newly added repository, can see all the folders. Click on parent folder and click ' Checkout ' to your work space.

Popular posts from this blog

Implementing autocompletion OTP field in iOS

Long waiting is over. !!  iOS 12 brings Autofill for OTP text field which is close to Android provided a decade back. Previously in iOS we used to toggle between OTP text screen and message inbox.  Which was hard to remember and time consuming resulting a bad user experience. Personally, I have been asked from the client/customer couple of times to implement autocompletion for OTP field and took me a lot of time to convey that it is not possible in iOS. Why Autofill was not possible previously?  We all know that Apple gives at most care for user privacy. When we see iOS architecture, each individual app is like a separate island. There is no inter-app bridge between apps (exception for Keychain and URLSchemes APIs which gives very limited scope). Thus we cannot read message content from inbox. Where to start Autofilling? First of all, the target SMS need to have the OTP Code with prefix string "Code" or "Passcode"on its message content. Beware of OTP c...

Animating label text update - choosing a better way

Recently I published a countdown app .  At one point of development - I have to show a timer on a UILabel which ticks on each seconds. As usual I started  setting text to a label object - self .timerLabel.text = someString Easy piece of cake right !?   But wait ... it won't take much user attention when timer ticks on every seconds. So I decided to make use of a simple animation while label gets text update. I found there are dozens of ways to animate a label. In this short article, I listed 3 best way you can animate text on a label. ( Spoiler Alert 👀- I decided to go with 3rd option)  1. Fade In - Fade out animation : CATransition class has got transition type `fade`. With timing function of CATransition - I was able to see the below result. let animation: CATransition = CATransition () animation.timingFunction = CAMediaTimingFunction (name: CAMediaTimingFunctionName .easeInEaseOut) animation.type = CATransitionType .fade animation.subtype = C...

Cached Async Image in SwiftUI

 SwiftUI’s AsyncImage is handy, but every time your view appears, it refetches the image—leading to flicker, delays, and unnecessary network use. What if you could fetch once, then reuse instantly? That's exactly what the Cached Async Image  delivers: a memory-powered caching layer that keeps SwiftUI image loading smooth, snappy, and resilient. First a simple in-memory cache without disk persistence. This will be thread-safe and auto-purges under memory pressure. A Singleton wrapping NSCache for URL → UIImage caching as follows : final class ImageCache {   static let shared = ImageCache()   private init() {}   private let cache = NSCache<NSURL, UIImage>()   func image(for url: URL) -> UIImage? {     cache.object(forKey: url as NSURL)   }   func insertImage(_ image: UIImage?, for url: URL) {     guard let image else { return }     cache.setObject(image, forKey: url as NSURL)   }   func clearAll() { ...

Prevent Navigationbar or Tabbar overlapping Subview - solved for Card view

Recently, I started with a Card view added as a subview of UIView in a view-controller. When a view controller created along subviews, it tends to use entire screen bounds and also slips behind Tab bar or Navigation bar. In my current situation, it's second case. Casually new iOS developers will write a patch by additional value for coordinate y and subtracting bar height from its size. A lot of them posted in SO threads too : How to prevent UINavigationBar from covering top of view? View got hidden below UINavigationBar iOS 7 Navigation Bar covers some part of view at Top So, how I got solved ? self.edgesForExtendedLayout = [] This  will avoid all subviews in a view controller get behind any bars. Read full apple  documentation on here. Full Source code below :  //Simple view controller where its view layed-out as a card. class WidgetCardViewController : UIViewController { var containerView = UIView () //MARK:- View Controller Life Cyc...

UICollectionViewCell shows with wrong size on First time - Solved

We commonly use Collection view where its cell size calculated run time. The flow layout delegate is responsible to return individual cell sizes. BUT in most of the cases, delegate method `collectionView: layout sizeForItem:` expects cell size too early. Before generating actual cell size. extension YourViewController : UICollectionViewDelegateFlowLayout { func collectionView ( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize (width: externalWidth, height: externalHeight) } } For instance, if a cell size depends on external view and its frame is not yet ready - results with wrong (or outdated) cell size. Typically happens for the first time view controller laid out all views. You can find similar queries in StackOverflow community : Collection view sizeForItemNotWorking UICollectionViewCell content wrong size on first load How to refresh UICollec...