Skip to content

Instantly share code, notes, and snippets.

Nuno Alexandre NunoAlexandre

Block or report user

Report or block NunoAlexandre

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View small-step-after.swift
observers.append(
NotificationCenter.default.addObserver(
forName: AVAudioSession.interruptionNotification,
object: nil,
queue: nil
)
{ [weak weakSelf = self] (notification) in
weakSelf?.onInterruption(notification)
}
)
View small-step-before.swift
observers.append(NotificationCenter.default.addObserver(forName: AVAudioSession.interruptionNotification, object: nil, queue: nil) { [weak weakSelf = self] (notification) in
weakSelf?.onInterruption(notification)
})
@NunoAlexandre
NunoAlexandre / User+FromJson.swift
Created Mar 25, 2019
Making User FromJson compliant
View User+FromJson.swift
extension User: FromJson {
static func from(value: JsonValue) -> User? {
return value.ifObject { json in
User(
id: try json .! "id",
name: try json .! "name",
email: json .? "email",
country: json .? "country",
subscription: try json .! "subscription",
favouriteSongs: (json ..? "favouriteSongs") ?? []
View storkExampleTypes.swift
struct User {
let id: Int
let name: String
let email: String?
let country: Country?
let subscription: Subscription
let favouriteSongs: [Song]
}
enum Subscription: String {
View downloadAfter.swift
@discardableResult
func attemptDownload(forItem item: Item) -> Promise<URL> {
if !canSubmitDownload(forItem: item) {
return Promise.reject(DownloadError.duplicatedDownload)
}
else if !SettingsManager.shared.canDownloadOrStream() {
let error = DownloadError.canNotUseInternet
self.registerFailedDownload(item, withError: error)
return Promise.reject(error)
}
@NunoAlexandre
NunoAlexandre / downloadBefore.swift
Created Mar 23, 2019
A callback hell downloading an item
View downloadBefore.swift
@discardableResult
func downloadSpecificActivity(activityInfo: SpecificActivityFirebase, completion: @escaping ((URL?, Error?) -> Void), progress: ((Double?) -> Void)? = nil) -> ContentDownload? {
if SettingsManager.shared.wifiOnlyEnabled && SettingsManager.shared.reachabilityManager?.isReachableOnWWAN ?? false {
completion(nil, ContentError.notAllowedOnWWanError)
} else if SettingsManager.shared.reachabilityManager != nil && !SettingsManager.shared.reachabilityManager!.isReachable {
completion(nil, ContentError.notConnected)
} else {
let downloadStartDate = Date.now()
if let tempUrl = temporaryDownloadUrl(forSpecificActivity: activityInfo) {
@NunoAlexandre
NunoAlexandre / createSlideshowTyped.swift
Last active Dec 23, 2018
Create Slideshow - Typed Modeling
View createSlideshowTyped.swift
let slides = [
Slide(
title: "Bobby Mcferrin",
description: "Jazz at its best",
image: UIImage(name: "BobbyMcferrin")!
),
Slide(
title: "Kurt Vile",
description: "A prolific creative",
image: UIImage(name: "KurtVile")!
@NunoAlexandre
NunoAlexandre / createSlideshowProcedural.swift
Created Dec 23, 2018
Create a Slideshow - Procedural Modeling
View createSlideshowProcedural.swift
let slideshow = Slideshow(
slides: [
SlideView(index: 0),
SlideView(index: 1),
SlideView(index: 2)
]
)
View typedModeling.swift
class Slideshow: UIView {
let slides: [SlideView]
// UI & Layout code goes here...
}
class SlideView: UIView {
let slide: Slide
// UI & Layout code goes here...
View proceduralModeling.swift
class Slideshow: UIViewController {
let slides: [SlideView]
init(slides: [SlideView]) {
self.slides = slides
}
// UI & Layout code goes here...
}
You can’t perform that action at this time.