I had this error when I was trying to build and run my iOS app on Xcode, I tried restarting my Mac nothing worked then I later searched for other error which was dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib
The problem could have arose after updating brew
Finally I found a solution here Answer by Goran, Hope you will find it helpful.
Hope you will find it helpful