iOS Development is easy with XCode, Swift3, UITableView, cocatouch, let's build iPhone, iPad and Macbook Applications.

Using Swift to disable sleep/screen saver for OSX

I’m looking for a way to disable sleep mode and screensaver through my application using Swift. I know this question has been asked before, but none of the answers are current (at least for Swift; I don’t know about Objective-C). I originally thought to use NSWorkspace.sharedWorkspace().extendPowerOffBy(requested: Int), but according to Apple’s documentation, it is currently […]

Google Sign-In via Firebase: GIDSignInDelegate does not conform to ViewController

I’m introducing Google Sign-In to my app and whilst both Google and Firebase documentation is thorough enough, what I have done as they suggested is not sufficient… I am still getting this error. Hopefully this will help others with finding a solution to the problem when implementing their SDK….thanks in advance for reviewing this chunky […]

FetchRequest – NSArray element failed to match the Swift Array Element type – Swift 2.0

I want to do a NSFetchRequest to display my data into a UICollectionView : import UIKit import CoreData let appDelegate: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate let context: NSManagedObjectContext = appDelegate.managedObjectContext class GarageViewController: UIViewController, UICollectionViewDelegate,UICollectionViewDataSource { @IBOutlet weak var backgroundView: UIImageView! @IBOutlet weak var collectionView: UICollectionView! var voitures: [Voiture] = [Voiture]() override func viewDidLoad() { super.viewDidLoad() […]

my UIViews muck-up when I combine UIPanGestureRecognizer and autolayout

I’d like a ball to track my finger as I drag it along a circular trajectory for every allowable device orientation on iPhone or iPad. Views appear to be correctly centred when a device is rotated but the ball will not stay on the circumference and seems to go anywhere when I drag it. EDIT […]

Swift: How to expand a tilde in a path String

How can I expand a path String with a tilde in Swift? I have a string like “~/Desktop” and I’d like to use this path with the NSFileManager methods, which requires the tilde to be expanded to “/Users/<myuser>/Desktop”. (This question with a clear problem statement doesn’t exist yet, this should be easily findable. Some similar […]

Swift 2.0 'unexpected trailing closure' error with lazy var assignment

I’m converting a project to Swift 2.0 and I keep coming across this error everywhere that I’m using a lazy var. This code works perfectly in 1.2 but breaks in 2.0: lazy private var placeholderImage = UIImage(named: “theImage”) But, this code generates an ‘unexpected trailing closure’ error in 2.0. Following the Xcode’s suggestions to fix […]

Detect phone calls on iOS with CTCallCenter (Swift)

I wanted to try to detect incoming phone calls in my app. I created a new Swift project from scratch just to try some code. The only thing I did was importing CoreTelephony in the ViewController that is created with every new project and I also changed the viewDidLoad() to: super.viewDidLoad() // Do any additional […]

iOS: UICollectionViewCell auto adjust size according to screen size

I am trying to create 10 cells in the collection view(same size as the screen). When I run my app in iphone5s simulator, the view contains exactly 5 cells. But when I switch to iphone6p simulator, the view contains more than 5 cells. How should I adjust the cell size so that the number of […]

Swift Constants file – class or struct?

I want to create a Constants file in my Swift project – filled with static let strings. Should I create as a struct or a class? And why?

How to get a low res image, or Thumbnail from the ALAssetRepresentation in Swift

I am working with the ALAssetLibrary to get the images from my camera roll for a custom view I am making. Doing so was pretty simple: library.enumerateGroupsWithTypes(ALAssetsGroupType(ALAssetsGroupSavedPhotos), usingBlock: { (group: ALAssetsGroup?, stop: UnsafeMutablePointer<ObjCBool>) in if group != nil { group!.setAssetsFilter(ALAssetsFilter.allPhotos()) var indexSet = NSIndexSet(indexesInRange: NSMakeRange(0, group!.numberOfAssets() – 1)) group!.enumerateAssetsAtIndexes(indexSet, options: nil, usingBlock: { (result: ALAsset!, […]