Prevent screen capture in an iOS app

I’ve just wrote simple extension of UIView that allows to hide it from screen-capturing, Airplay mirroring and so on. The solution uses ability of UITextField to hide a password from capturing. extension UIView { func makeSecure() { DispatchQueue.main.async { let field = UITextField() field.isSecureTextEntry = true self.addSubview(field) field.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true field.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true … Read more

What is NSManagedObjectContext’s performBlock: used for?

The methods performBlock: and performBlockAndWait: are used to send messages to your NSManagedObjectContext instance if the MOC was initialized using NSPrivateQueueConcurrencyType or NSMainQueueConcurrencyType. If you do anything with one of these context types, such as setting the persistent store or saving changes, you do it in a block. performBlock: will add the block to the … Read more

When should translatesAutoresizingMaskIntoConstraints be set to true?

translatesAutoresizingMaskIntoConstraints needs to be set to false when: You Create a UIView-based object in code (Storyboard/NIB will set it for you if the file has autolayout enabled), And you want to use auto layout for this view rather than frame-based layout, And the view will be added to a view hierarchy that is using auto … Read more

How can I change a SwiftUI Color to UIColor?

SwiftUI 2.0 There is a new initializer that takes a Color and returns a UIColor for iOS or NSColor for macOS now. So: iOS UIColor(Color.red) macOS NSColor(Color.red) Core Graphics UIColor(Color.red).cgColor /* For iOS */ NSColor(Color.red).cgColor /* For macOS */ If you are looking for color components, you can find a helpful extensions here in this … Read more

Different ways of getting current interface orientation?

self.interfaceOrientation returns UIInterfaceOrientation, current orientation of the interface. It is a property in UIViewController, you can access to this one only in UIViewController classes. [[UIApplication sharedApplication] statusBarOrientation] returns UIInterfaceOrientation, current orientation of the application’s status bar. You can access to that property in any point of your application. My experience shows that it’s more effective … Read more