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 android.content.Context; | |
import android.content.SharedPreferences; | |
import android.os.AsyncTask; | |
import android.support.annotation.Nullable; | |
import android.util.Log; | |
import android.util.Pair; | |
import com.google.android.gms.common.ConnectionResult; | |
import com.google.android.gms.common.GooglePlayServicesUtil; | |
import com.google.android.gms.gcm.GoogleCloudMessaging; |
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
static NSString *encodeText(NSString *string, int key) | |
{ | |
NSMutableString *result = [[NSMutableString alloc] init]; | |
for (int i = 0; i < [string length]; i++) | |
{ | |
unichar c = [string characterAtIndex:i]; | |
c += key; | |
[result appendString:[NSString stringWithCharacters:&c length:1]]; | |
} | |
return result; |
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 ReusableCell: AnyObject { | |
static func reuseIdentifier() -> String? | |
static func uiNibFromClass() -> UINib? | |
} |
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 ReusableCell where Self: UICollectionViewCell { | |
static func uiNibFromClass() -> UINib? { | |
return UINib(nibName: Self.className, bundle: nil) | |
} | |
static func reuseIdentifier() -> String? { | |
return Self.className | |
} | |
} |
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)) |
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
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
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
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
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 | |
{ |
OlderNewer