This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Le "Optionnal Chaining" permet d'effectuer une action, | |
uniquement si la variable à l'origine de l'action n'est pas égale à nil. | |
*/ | |
result = retourneParfoisNil(true) //result égale 10 | |
print(result?.getMirror()) // result égale "Optional(Swift._LeafMirror<Swift.Int>(_value: 10, summaryFunction: (Function), quickLookFunction: (Function)))" | |
result = retourneParfoisNil(false) // result égale nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Le "Optionnal Binding" permet de créer une variable à partir d'une autre, | |
uniquement si cette dernière n'est pas égale à nil | |
*/ | |
result = retourneParfoisNil(true) //result égale 10 | |
if let resultTemp = result { | |
print("OK j'ai été créé") // On tombe dans le IF - S'affiche bien car result = 10 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var result: Int? | |
result = result + 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let day = DayModel(id: idOfDay, | |
idDate: Int(time.dayTimePeriodFormatter.string(from: date))!, | |
title: String(fullDate.characters.prefix(1)).uppercased() + String(fullDate.characters.dropFirst()), | |
email: email)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let idDate: Int = Int(time.dayTimePeriodFormatter.string(from: date))! | |
var title: String = String(fullDate.characters.prefix(1)).uppercased() | |
let titleEnd: String = String(fullDate.characters.dropFirst()) | |
title.addString(titleEnd) | |
day = DayModel(id: idOfDay, | |
idDate: idDate, | |
title: title, | |
email: email)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if let resultJson: [String:AnyObject] = response.result.value as! [String:AnyObject]!{ | |
if let jsonItem = resultJson["access_token"] { | |
if jsonItem.description != nil { | |
AlamofireLRQDO.saveToken(resultJson["access_token"]!.description) | |
completion(Constantes.responseOK) | |
} else { | |
completion(Constantes.responseFailed) | |
} | |
} else { | |
completion(Constantes.responseFailed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if let resultJson: [String:AnyObject] = response.result.value as! [String:AnyObject]!{ | |
if let jsonItem: NSString = resultJson["access_token"] as? NSString{ | |
AlamofireLRQDO.saveToken(jsonItem.description) | |
completion(CookMinuteConstantes.responseOK) | |
} else { | |
completion(CookMinuteConstantes.responseFailed) | |
} | |
} else { | |
completion(CookMinuteConstantes.responseFailed) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getAllStates(_ email: String, todayDate: Int) -> Array<ListeDeCourseStateModel> { | |
let realm = try! Realm() | |
let predicate = NSPredicate(format: "parentID = '"+email+"' AND idDayRef >= "+todayDate.description) | |
return realm.objects(ListeDeCourseStateEntity.self).filter(predicate).toModels() | |
} | |
func getStateForIngredient(_ ingredientID: String, email: String) -> Results<ListeDeCourseStateEntity>{ | |
let realm = try! Realm() | |
let predicate = NSPredicate(format: "ingredientRef.id = '"+ingredientID+"' AND parentID = '"+email+"'") | |
return realm.objects(ListeDeCourseStateEntity.self).filter(predicate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getAllStates(_ email: String, todayDate: Int) -> Array<ListeDeCourseStateModel> { | |
let realm: Realm = try! Realm() | |
var format: String = "parentID = '" | |
format.addString(email) | |
format.addString("' AND idDayRef >= ") | |
format.addString(todayDate.description) | |
let predicate: NSPredicate = NSPredicate(format: format) | |
return realm.objects(ListeDeCourseStateEntity.self).filter(predicate).toModels() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension RealmCollection where Element == ListeDeCourseStateEntity { | |
func toModels() -> Array<ListeDeCourseStateModel> { | |
var list: Array<ListeDeCourseStateModel>= Array<ListeDeCourseStateModel>() | |
for value in self { | |
list.append((value as! ListeDeCourseStateEntity).toModel()) | |
} | |
return list | |
} | |
} |
OlderNewer