Tuesday, November 2, 2021

How to handle unhandled exceptions like SIGTRAP

https://www.cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html


void InstallUncaughtExceptionHandler()

{

    NSSetUncaughtExceptionHandler(&HandleException);

    signal(SIGABRT, SignalHandler);

    signal(SIGILL, SignalHandler);

    signal(SIGSEGV, SignalHandler);

    signal(SIGFPE, SignalHandler);

    signal(SIGBUS, SignalHandler);

    signal(SIGPIPE, SignalHandler);

}

Tuesday, June 15, 2021

toString print all the fields

 public func toString() -> String {

    var ret = "Test Status: "

    for case let (label?, value) in Mirror(reflecting: self)

      .children.map({ ($0.label, $0.value) }) {

      ret.append(" \(label): \(value)")

    }

    return ret

  }


Wednesday, May 5, 2021

View files generated in documents folder in the Files app

 <key>UIFileSharingEnabled</key>

    <true/>

<key>LSSupportsOpeningDocumentsInPlace</key>

    <true/>

How to generate a file in documents folder

 public func createAndWriteFile() {

     let fileName = "sample"

     let documentDirectoryUrl = try! FileManager.default.url(

        for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true

     )

     let fileUrl = documentDirectoryUrl.appendingPathComponent(fileName).appendingPathExtension("txt")

     // prints the file path

     print("File path \(fileUrl.path)")

     //data to write in file.

     let stringData = "Hello Tutorials Point"

     do {

        try stringData.write(to: fileUrl, atomically: true, encoding: String.Encoding.utf8)

     } catch let error as NSError {

        print (error)

     }

  }

Thursday, April 29, 2021

Thursday, January 14, 2021

How to disable a modal from swiping down to close

let vc = DetailViewController() vc.isModalInPresentation = true present(vc, animated: true)

Wednesday, January 13, 2021

adding borders

 extension UIView {

    func addTopBorderWithColor(color: UIColor, width: CGFloat) {

        let border = CALayer()

        border.backgroundColor = color.cgColor

        border.frame = CGRect(x:0,y: 0, width:self.frame.size.width, height:width)

        self.layer.addSublayer(border)

    }


    func addRightBorderWithColor(color: UIColor, width: CGFloat) {

        let border = CALayer()

        border.backgroundColor = color.cgColor

        border.frame = CGRect(x: self.frame.size.width - width,y: 0, width:width, height:self.frame.size.height)

        self.layer.addSublayer(border)

    }


    func addBottomBorderWithColor(color: UIColor, width: CGFloat) {

        let border = CALayer()

        border.backgroundColor = color.cgColor

        border.frame = CGRect(x:0, y:self.frame.size.height - width, width:self.frame.size.width, height:width)

        self.layer.addSublayer(border)

    }


    func addLeftBorderWithColor(color: UIColor, width: CGFloat) {

        let border = CALayer()

        border.backgroundColor = color.cgColor

        border.frame = CGRect(x:0, y:0, width:width, height:self.frame.size.height)

        self.layer.addSublayer(border)

    }


    func addMiddleBorderWithColor(color: UIColor, width: CGFloat) {

        let border = CALayer()

        border.backgroundColor = color.cgColor

        border.frame = CGRect(x:self.frame.size.width/2, y:0, width:width, height:self.frame.size.height)

        self.layer.addSublayer(border)

    }

}


Thursday, January 7, 2021

How to generate a app size report

xcodebuild -exportArchive -archivePath iOSApp.xcarchive -exportPath Release/MyApp -exportOptionsPlist OptionsPlist.plist