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
class Usage { | |
companion object { | |
fun loadStuff(image: SimpleDraweeView, imageURI: String) { | |
image.setImageURI(imageURI) | |
} | |
} | |
} | |
class SetupExample { | |
companion object { |
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
object Versions { | |
val kotlin = "1.2.21" | |
val supportLib = "27.0.2" | |
val buildTools = "27.0.2" | |
val minSDK = 19 | |
val targetSDK = 26 | |
val compileSDK = 26 | |
val versionCode = 1 | |
val versionName = "1.0" |
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
// This script will configure the deploy to bintray with aar | |
// Of an android-library using kotlin project | |
// Simply by providing the .property files | |
// all boilerplate code is here. | |
apply plugin: 'com.github.dcendents.android-maven' | |
apply plugin: 'com.jfrog.bintray' | |
apply plugin: 'org.jetbrains.dokka-android' | |
apply plugin: 'maven-publish' |
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
class ExampleViewController: UIViewController { | |
@IBOutlet weak var collectionView: UICollectionView! | |
// the compiler will now complain if you don't have this implemented | |
// you need this to conform to SegueHandlerType | |
enum SegueIdentifier: String { | |
case TheRedPillExperience | |
case TheBluePillExperience | |
} |
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
protocol SegueHandlerType { | |
associatedtype SegueIdentifier: RawRepresentable | |
} | |
// notice the cool use of where here to narrow down | |
// what could use these methods. | |
extension SegueHandlerType where Self: UIViewController, | |
SegueIdentifier.RawValue == String | |
{ |
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
class ExampleViewController: UIViewController { | |
@IBOutlet weak var collectionView: UICollectionView! | |
override func viewDidLoad() { | |
title = "Example title".localized() | |
collectionView.registerCell(ExampleCell) | |
} | |
} | |
Localization files example: |
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
public class Localize: NSObject { | |
/** | |
List available languages | |
- Returns: Array of available languages. | |
*/ | |
public class func availableLanguages() -> [String] { | |
return NSBundle.mainBundle().localizations | |
} | |
/** |
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
public extension String { | |
/** | |
Swift 2 friendly localization syntax, replaces NSLocalizedString | |
- Returns: The localized string. | |
*/ | |
func localized() -> String { | |
if let path = NSBundle.mainBundle().pathForResource(Localize.currentLanguage(), ofType: "lproj"), bundle = NSBundle(path: path) { | |
return bundle.localizedStringForKey(self, value: nil, table: nil) | |
} | |
else if let path = NSBundle.mainBundle().pathForResource(LCLBaseBundle, ofType: "lproj"), bundle = NSBundle(path: path) { |
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
class ExampleCell: UICollectionViewCell, ReusableCell { | |
func updateCellUI() { | |
print("Here you should do something") | |
} | |
} | |
class ExampleViewController: UIViewController { | |
@IBOutlet weak var collectionView: UICollectionView! | |
override func viewDidLoad() { |
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 UICollectionView { | |
func registerCell<T: ReusableCell>(cellType: T.Type) { | |
if let identifier = T.reuseIdentifier() { | |
self.registerNib(T.uiNibFromClass(), forCellWithReuseIdentifier: identifier) | |
} | |
} | |
func dequeueReusableCell<T: UICollectionViewCell>(index: Int) -> T { | |
return dequeueReusableCell(NSIndexPath(forItem: index, inSection: 0)) |
NewerOlder