Example from Android Jetpack: LiveData
MutableLiveData Example |
---|
![]() |
MutableLiveData Example |
---|
![]() |
import javax.crypto.Cipher; | |
import javax.crypto.spec.IvParameterSpec; | |
import javax.crypto.spec.SecretKeySpec; | |
import java.util.Base64; | |
public class Encryptor { | |
public static String encrypt(String key, String initVector, String value) { | |
try { | |
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); | |
IvParameterSpec iv = new IvParameterSpec(initVector.getBytes("UTF-8")); |
# the instructions from here: https://stackoverflow.com/questions/3704919/installing-rmagick-on-ubuntu/31089915#31089915 | |
# worked, but only after I added in line 8 | |
sudo apt-get purge graphicsmagick graphicsmagick-dbg imagemagick-common imagemagick imagemagick-6.q16 libmagickcore-6-headers libmagickwand-dev graphicsmagick-libmagick-dev-compat | |
sudo apt-get autoremove | |
sudo apt-get install imagemagick libmagickwand-dev | |
sudo ln -s /usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16/Magick-config /usr/bin/Magick-config | |
export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig | |
gem install rmagick |
override func viewDidAppear(_ animated: Bool) { | |
var frame = tableView.frame | |
frame.size.height = tableView.contentSize.height | |
tableView.frame = frame | |
tableviewHeightConstraint.constant = tableView.contentSize.height | |
} |
extension String { | |
var twoFractionDigits: String { | |
let styler = NumberFormatter() | |
styler.minimumFractionDigits = 2 | |
styler.maximumFractionDigits = 2 | |
styler.numberStyle = .currency | |
let converter = NumberFormatter() | |
converter.decimalSeparator = "." | |
if let result = converter.number(from: self) { | |
return styler.string(for: result) ?? "" |
// | |
// AdDetailVC.swift | |
// | |
// | |
// Created by GriSoft Mobile on 31.03.2018. | |
// Copyright © 2018 All rights reserved. | |
// | |
import UIKit |
let formatter = NumberFormatter() | |
formatter.generatesDecimalNumbers = true | |
formatter.numberStyle = NumberFormatter.Style.decimal | |
if let formattedNumber = formatter.number(from: textValue) as? NSDecimalNumber { | |
xa = formattedNumber | |
} |
//Xib class | |
import UIKit | |
protocol CustomViewDelegate: class { // make this class protocol so you can create `weak` reference | |
func goToNextScene() | |
} | |
class CustomView: UIView { | |
weak var delegate: CustomViewDelegate? // make this `weak` to avoid strong reference cycle b/w view controller and its views |
extension UIImage { | |
func tinted(color: UIColor) -> UIImage { | |
UIGraphicsBeginImageContext(self.size) | |
guard let context = UIGraphicsGetCurrentContext() else { return self } | |
guard let cgImage = cgImage else { return self } | |
// flip the image | |
context.scaleBy(x: 1.0, y: -1.0) |