OSX application without storyboard or xib files using Swift

if you don’t want to have the @NSApplicationMain attribute, do: have a file main.swift add following top-level code: import Cocoa let delegate = AppDelegate() //alloc main app’s delegate class NSApplication.shared.delegate = delegate //set as app’s delegate NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv) //start of run loop // Old versions: // NSApplicationMain(C_ARGC, C_ARGV) // NSApplicationMain(Process.argc, Process.unsafeArgv); the rest should be … Read more

How do you write a completion handler in Swift 3?

In Swift 3 the function parameter labels in closures are gone. Remove all occurrences of success: and add @escaping func Logout(completionHandler:@escaping (Bool) -> ()) { backendless?.userService.logout( { user in print(“User logged out.”) completionHandler(true) }, error: { fault in print(“Server reported an error: \(fault)”) completionHandler(false) }) } And use it Logout() { success in print(success) }

How to display an image using URL?

The error is most likely that imageURL is nil. Are you assigning it a value elsewhere in the code, or is it actually @IBOutlet in the real code? If you do not assign a value to it, it will be nil – but its type of UIImageView! means it is an “implicitly unwrapped optional” which … Read more

Array element cannot be bridged to Objective-C

The reason Objective-C is mentioned is because UIKit and QuartzCore are Objective-C frameworks. In particular, gradient.colors = arrayColors is calling an Objective-C method that expects an NSArray. This seems like a bug, as Apple’s documentation makes it sound like that the array should auto-bridge to an NSArray so long as the items in the array … Read more

How do I use the metadataOutputRectOfInterestForRect method and rectOfInterest property to scan a specific area? (QR Code)

I wasn’t really able to clarify the issue with metadataOutputRectOfInterestForRect, however, you can directly set the property as well. You need to the have the resolution in width and height of your video, which you can specify in advance. I quickly used the 640*480 setting. As stated in the documentation, these values have to be … Read more

Warning: UICollectionViewFlowLayout has cached frame mismatch for index path ‘abc’

This is likely occurring because the flow layout “xyz” is modifying attributes returned by UICollectionViewFlowLayout without copying them And sure enough, that’s just what you are doing: private override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? { let attributes = super.layoutAttributesForItemAtIndexPath(indexPath) let distance = CGRectGetMidX(attributes!.frame) – self.midX; var transform = CATransform3DIdentity; transform = CATransform3DTranslate(transform, -distance, 0, -self.width); … Read more

iOS11 photo library access is possible even if settings are set to “never”

Okay, you can sort of piece this together from answers and comments already, but to try to tell a more complete story… In iOS 11, UIImagePickerController runs as a separate process from your app. That means: Your app can’t see the user’s whole Photos library — it gets read-only access just for whichever asset(s) the … Read more