Don't wanna be here? Send us removal request.
Text
Result enum blocks
enum Result<T> { case Success (result: T) case Error (error: Error) }
typealias ResultBlock<T> = (Result<T>) -> ()
unwrapping:
switch result { case .Success (let success): case .Error (let error): }
passing:
completion(Result.Success(result: value))
0 notes
Text
Notifications permissions
The simplest way to ask user for permission is just:
But sometimes we want to show user alert and only show request permission if user agrees. If user won’t allow pushes he has to change it in system settings, we can’t change it from the app.
So we can show simple alert controller and then ask for permission if user agrees.
But there’s a problem - every time the code executes user will be prompted to allow notification, even If he already allowed notifications.
We can get settings from UNNotificationCenter and check authorizationStatus to resolve it:
0 notes
Text
Health Kit - permissions
What we should do to be able to access Health Kit data?
1. Go to 'Project Settings'->'Capabilities' and turn on HealthKit. I’ll generate unique app id for your app.
2. Add method in AppDelegate to handle authorisation request.
3. It’s necessary to add some keys in Info.plist file - If you don’t do this HealthKit authorisation screen won’t appear. The values that you enter will be displayed on request authorisation popup.
* Health Share Usage Description * Health Update Usage Description
4. Request authorization. Example code to request access to heartRate from Apple Watch:
0 notes
Text
Init UIView from nib
How to init custom UIView from nib?
1. Create CustomView.swift and CustomView.xib.
2. In CustomView.xib change ‘File’s Owner’ class to CustomView. (DO NOT change View class).
3. In CustomView.swift implement init and set up view.
4. In storyboard set your UIView class to CustomView, create outlet and check if it’s working :).
5. Bonus - @IBDesignables. Add following line of code to your custom UIView class.
6. Go into your custom view in Storyboard, compile and the view should render itself. (If not go to Editor and click Refresh All Views).
0 notes
Text
1px separators
Sometimes in the app we want to make a delicate separator.
Setting it’s size to 1pt is often too much - it renders to 2 or 3px (depends on the device). So can can we make separator that renders to 1px on every device?
Fortunately, it’s quite easy to do:
0 notes