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 arrayToMaster = [7, 2, 10, 4, 5] | |
arrayToMaster.sort(by: <) | |
print(arrayToMaster) | |
arrayToMaster.sort { s1, s2 in | |
s1 > s2 | |
} |
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
- (void) URLRequestObjCParaOCDN { | |
//descomenta isto ---> //__weak "nomeDaClasseOndeTensIsto" *weakSelf = self; //nao uses self. em lado nenhum no block, usa weakSelf. nao pode originar leaks e é igual #proTip | |
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"o teu link aqui"]]; | |
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler: | |
^(NSData *data, NSURLResponse *response, NSError *error) { | |
//Ele so executa isto quando o request e finalizado, isto e executado numa background thread. Se aqui dentro precisares de usar um "self." diz-me que ensino-te a fazer um weakify ao self para nao teres um memory leak. O "error" so traz erros quando nao tens net e assim, o data é onde vem o json ou o erro do body, o response e onde veem os headers. | |
if (error == nil) { //isto assume que o request foi successfull a nivel de execucao, nao de integridade de dados |
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 UIApplication { | |
class var statusBarBackgroundColor: UIColor? { | |
get { | |
return (shared.value(forKey: "statusBar") as? UIView)?.backgroundColor | |
} set { | |
(shared.value(forKey: "statusBar") as? UIView)?.backgroundColor = newValue | |
} | |
} | |
} |
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 UIApplication { | |
class var statusBarBackgroundColor: UIColor? { | |
get { | |
return (shared.value(forKey: "statusBar") as? UIView)?.backgroundColor | |
} set { | |
(shared.value(forKey: "statusBar") as? UIView)?.backgroundColor = newValue | |
} | |
} | |
} |
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
[ | |
{ | |
"account_id": "7ad216c0-df13-42fc-902a-3ef5778029d0", | |
"created_at": "2017-03-20 15:40:15", | |
"customer_id": "00000000-0000-0000-0000-000000000001", | |
"display_id": "61777", | |
"id": "f1c61484-87b2-4133-96bf-6933d277cf67", | |
"last_seen_at": "2017-03-24 10:46:32.010368", | |
"native_id": "61777", | |
"provider_native_details": { |
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 UIImage { | |
class func disclosureIndicator() -> UIImage? { | |
let disclosureCell = UITableViewCell() | |
disclosureCell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator | |
for view in disclosureCell.subviews { | |
if let button = view as? UIButton { |
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
import CoreData | |
extension NSManagedObject { | |
class var entityName: String! { | |
get { | |
return self.entity().managedObjectClassName.components(separatedBy: ["."]).last! | |
} | |
} | |
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 registerForPushNotifications(application: UIApplication) { // just call this on idFinishLaunchingWith options | |
let notificationSettings = UIUserNotificationSettings( | |
types: [.badge, .sound, .alert], categories: nil) | |
application.registerUserNotificationSettings(notificationSettings) | |
} | |
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) { | |
if notificationSettings.types != .none { |