sizeForItemAt of UICollectionView not working in Swift


There was a requirement where I was setting custom size for UICollectionViewCell. Custom size wasn’t dynamic but a static tall portrait ratio size. The effective way to set your own custom size is to call implement delegate method of protocol UICollectionViewDelegateFlowLayout:

func collectionView_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return estimatedCollectionSize

The problem:

UICollectionView was ignoring size instruction. It was sizing the cells to fit its content only.


Password Laravel Personal/Password Access Client Not Found


We must have stumbled on Laravel’s passport sometime for creating authentication api’s for our mobile apps providing full OAuth2 server implementation.

This post uses Laravel 7.x. Our passport installation is

composer require laravel/passport “~9.0”

We will perform the migration where Passport migrations will create the tables our application needs to store clients and access tokens. It will also create Users table for us.

php artisan migrate

We also updated the driver to use passport in config/auth.php

‘api’ => [
            ‘driver’ => ‘passport’,
            ‘provider’ => ‘users’,
            ‘hash’ => false,

Now in our registration api example when we try to generate access token

$user->createToken(‘MyApp Password Grant Client’)->accessToken;

It gives error:

Auth driver [passport] for guard [api] is not defined.
Personal access client not found.


Get Push Notification While App in Foreground iOS in Swift


If the application is running in the foreground, iOS won’t show a notification banner or alert. That is by design.

If we receive local or remote notifications while we app is running in the foreground, we’re responsible for passing the information to our users in an app-specific way. Where to handle and process such request?


Asks the delegate how to handle a notification that arrived while the app was running in the foreground.

If your app is in the foreground when a notification arrives, the shared user notification center calls this method to deliver the notification directly to your app. If you implement this method, you can take whatever actions are necessary to process the notification and update your app. When you finish, call the completionHandler block and specify how you want the system to alert the user, if at all.


Present Safari View Controller Modally instead of Push


When I launch safari view controller(SFSafariViewController) by way of present(_:animated:completion:) method, I do not get the default modal transition behaviour, instead the transition is that of push (sliding in from the right), as if I called pushViewController:animated:


An object that provides a visible standard interface for browsing the web.

Adding two numbers in macOS x86-64 Assembly - Part 2


This is the second part as continuation of series “My first x86-64 assembly in macOS”. Please read first part to view assembly language programming from the perspective of total beginner. I thought simple addition of two numbers in assembly could be the next simple step in progress to learn assembly language programming, covering declaration of variable(kinda), accessing them, adding them and printing them. Hoping to give some more insights on assembly language programming adventure. This post follows same spirit of exploring the findings and observation through perspective of total beginner. If any information provided seems wrong please email me with explanation so I could understand and rectify. Most of the concepts we did explored in first part of the series but I will try to do very short brief here too.

I am using Intel based Mac running Catalina. In future when arm based Mac comes out, then this series may need to be interpreted separately. I am using AT&T syntax throughout the series.

Important Note:

Following assembly code may not be optimised. This assembly code to calculate the sum of numbers is for simple learning of following concepts:
  • Declare and Initialise variables in assembly.
  • Access variables in assembly.
  • Perform addition on variables in assembly.
  • Print the sum of variables in assembly.

Let’s start


How To Recover Password in Raspberry Pi


It has been 2 years since I worked on my raspberry pi. I was making an attempt to connect my raspberry pi from macbook via SSH.

ssh pi@192.168.x.x

It asked for password to connect and well…I don’t remember Password of raspberry pi anymore.

The default password on Raspberry Pi OS is raspberry. During fresh installation 2 years ago when I was enabling ssh I had changed default to my own password.

Please Note: I am using Jessie. The following instructions may not be valid anymore for newer version.

I tried the pi configuration utility tool. It allows you to change the password. But it also requires you to input current password to continue. It takes me back to start of the problem. After searching through various helpful instructions in forums I stumbled into very easy solution that didn’t require me to eject my SD Card, plug it in different computer and do change in files etc.


How to Send Local Video to iMessage in Swift


This post assumes we have understanding about exporting to mp4 video. The use case example of the discussion exports a video and save it locally inside app’s folder: Document, Cache or Temporary. In my case I am doing some very basic composing of video and saving it to my temporary folder. I want to send this video or share it to my contacts through iMessage or MFMessageComposeViewController. Below is a brief idea on how I am exporting to mp4 video that saves in app’s temporary folder.

let exportURL = URL(fileURLWithPath: NSTemporaryDirectory())
export.outputFileType = .mp4
export.outputURL = exportURL

export.exportAsynchronously {
  DispatchQueue.main.async {
    switch export.status {
    case .completed:
      print("Something went wrong during export.")
      print(export.error ?? "unknown error")

Now, I found 2 easy effective ways to share or attach video to iMessage or MFMessageComposeViewController.


How to get Deprecated keyWindow in Swift


Note: Discussion in this post assumes we are considering single window based scenario.

Sometimes I need to access the main window of my app to add some temporary views to it - making it appear forefront no matter at what depth of user’s navigation-flow I am in.

From old days of single window based app we have been using very convenient property handed to us: keyWindow

This property holds the UIWindow object in the windows array that is most recently sent the makeKeyAndVisible() message.

guard let window = UIApplication.shared.keyWindow else {return}

It has been long time. Now this has been deprecated from iOS 13 onwards.

We have our windows accessible from windows array:

let window = UIApplication.shared.windows[0]

A free assumption would be that first window in array would be the main window of the app - being the root. We want the root window so that any view being added be directly on top for our given purpose here. It worked good until unexpected happened. First object did not give UIWindow but UITextEffectsWindow. I could not add my view on the top anymore - adding to UITextEffectsWindow didn’t work for curiosity.


How to Display Image in SKShapeNode


I have been using SKShapeNode extensively to draw quick graphics by filling them with CGPaths for quick visual debugging and making prototypes. For example I can create procedural mountains quickly with SKShapeNode. In early times of spritekit SKShapeNode didn’t have way to render images on it. We have fillTexture available now that allows texture to fill the shape.

let shapeNode = SKShapeNode()
shapeNode.fillTexture = SKTexture(imageNamed: “testImage")

But, Our SKShapeNode is displaying nothing.

Why is that?


App crashing when saving photos from WKWebView


I stumbled upon a crash in my app. In my app I have a WKWebView that lets user access web. I tried saving image from a website by long pressing - general way we do in our iOS safari - and app crashed. This user experience behaviour of long pressing and saving image is very common.

The crash error is:

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSPhotoLibraryAddUsageDescription key with a string value explaining to the user how the app uses this data.


Recommended posts