Swift HMAC doesn’t match NodeJS HMAC, but only sometimes!

I have discovered a HUGE issue in my code, and I have literally no idea what is causing this.

SO, when I send requests to my server I hash a string thats in the request. This is sometimes user input.

My app is multi language so I have to support all “ä” chars etc.

So with the normal english letters/chars numbers etc, this hashing method works like a dream. BUT when the string being hashed and compared contains a “ä” or a “ö” (Not specifically those, it literally might be that any char not in the Base64 set will cause this) the hash doesn’t match!

This is an absolute and complete disaster, and I have not noticed it this far. I have tried basically everything I know to try to fix this, and googling, and I am out of luck so far.

I generate the hash in Swift inputting the string and secretToken into this function and saving the output as a HTTP header:

func hmac(string: String, key: String) -> String {      var digest = [UInt8](repeating: 0, count: Int(CC_SHA256_DIGEST_LENGTH))      CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA256), key, key.count, string, string.count, &digest)      let data = Data(digest)      return data.map { String(format: "%02hhx", $  0) }.joined()  } 

How I compare the hash in NodeJS:

if (hashInTheRequest === crypto.createHmac('sha256', secretToken).update(stringToHash).digest('hex')) {     //Good to go } 

Thanks in advance!

Como cambiar el color de los item generados en la pestaña ‘MORE’ en un Tab Bar controller en swift

He creado un controlador Tab bar y cuando agrego más de 6 items se auto genera un pestaña llamada ‘MORE’ en el cual se listan los demás items que se agreguen.

El problema que tengo es que cuando en el appdelegate.swift cambio el color de todos los tableview a un fondo color negro, el texto de los items de la pestaña ‘MORE’ se oculta porque son color negro, y no he encontrado la forma de modificar el color del texto de los item, lo único que he podido hacer es cambiar el color de los iconos de tableview.

AYUDA!!! 🙁

Así de muestra el tableview con el texto de los items oculto

error: ld-2.27.so in swift on Ubuntu 18.04

I’m installed swift on my ubuntu 18.04 and when i start i get this error. but the code works fine when i’m writing them, I search some solution to fix this error but the thing is that i will remove the libc6-dbg. is it okay to remove this, and my other works wont effect after i deleted this? or should I ignore the swift error ld-2.27.so since my code working.

error: ld-2.27.so 0xffffffff0005c564: adding range [0x1464a-0x146ba) which has a base that is less than the function's low PC 0x14dc0. Please file a bug and attach the file at the start of this error message error: ld-2.27.so 0xffffffff0005c564: adding range [0x146d0-0x146d6) which has a base that is less than the function's low PC 0x14dc0. Please file a bug and attach the file at the start of this error message error: ld-2.27.so 0xffffffff0005c5c5: adding range [0x1464a-0x146ba) which has a base that is less than the function's low PC 0x14dc0. Please file a bug and attach the file at the start of this error message error: ld-2.27.so 0xffffffff0005c5c5: adding range [0x146d0-0x146d6) which has a base that is less than the function's low PC 0x14dc0. Please file a bug and attach the file at the start of this error message Welcome to Swift version 5.0.2 (swift-5.0.2-RELEASE). 

NAVIGATIONBAR Swift perzonalizado

Mi objetivo es poder agregarle al navigationBar una barra lateral que sea de color diferente actualmente se ve asi

introducir la descripción de la imagen aquí

Quisiera lograr algo asi :

introducir la descripción de la imagen aquí

Mi codigo es el siguiente

func setupNavigationBar(showBack:Bool, showMenu:Bool,isLogin:Bool) {     self.navigationController?.navigationBar.isTranslucent = true      var leftItemTitle = UIBarButtonItem()     var backgroundItem = UIBarButtonItem()       let sizeLength = UIScreen.main.bounds.size.height * 2     let defaultNavigationBarFrame = CGRect(x: 0, y: 0, width: sizeLength, height: 70)      let mediumView = UIView()     let frame = self.navigationController?.navigationBar.frame.size     mediumView.frame = CGRect(x: 0, y: 0, width: frame!.width,  height: frame!.height)     mediumView.backgroundColor = UIColor.red      let titleLabel = UILabel()     titleLabel.text = self.menuText     titleLabel.font = UIFont.systemFont(ofSize: 20)     titleLabel.textColor = UIColor.white     titleLabel.sizeToFit()        leftItemTitle = UIBarButtonItem(customView: titleLabel)       if(!showBack && !showMenu && !isLogin){         self.navigationController?.navigationBar.tintColor = UIColor.clear         self.navigationItem.leftBarButtonItems?.removeAll()         self.navigationItem.setHidesBackButton(true, animated:false);         self.navigationController?.navigationBar.barTintColor = Utils.Color.LigthViewBackGround     }     else if(showBack){         let backMenuButtonItem = UIBarButtonItem(image: UIImage.init(named: "backButton"), style: UIBarButtonItemStyle.done, target: self, action: #selector(backPressed))         backMenuButtonItem.tintColor = UIColor.white         backMenuButtonItem.width = CGFloat(30)          self.navigationItem.leftBarButtonItems = [backMenuButtonItem,leftItemTitle,]             self.navigationController?.navigationBar.barTintColor = Utils.Color.backgroundBlue      }     else if(showMenu){         let sideMenuButtonItem = UIBarButtonItem(image: UIImage.init(named: "sideMenu"), style: UIBarButtonItemStyle.done, target: self, action: #selector(sideMenuPressed))         sideMenuButtonItem.tintColor = UIColor.white         sideMenuButtonItem.width = CGFloat(30)          let vistaAzul = UIView(frame: CGRect (x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 30 ))         vistaAzul.backgroundColor = Utils.Color.BlueLabelText 

// self.navigationController?.navigationBar.addSubview(vistaAzul) self.navigationItem.leftBarButtonItems = [sideMenuButtonItem,leftItemTitle]

    }     else if (isLogin){            self.navigationController?.navigationBar.barTintColor = Utils.Color.backgroundLogin     }         if let hidden = navigationController?.navigationBar.isHidden     {         if(hidden)         {             self.navigationController?.navigationBar.barStyle = .default         }         else         {             self.navigationController?.navigationBar.barStyle = .black         }     }   } 

radiant swift keto

http://www.trendysupplement.com/radiant-swift-keto/

radiant swift keto At the point when individuals began taking dietary enhancement in past occasions around then there is no extent of keto diets and individuals are not getting quicker outcomes. As the time passes headways are included the item like including of ketogenic equation this…

radiant swift keto

SETERROR SWIFT – Parecido a Android

En primero lugar mi objetivo es poder replicar el seterror de Android en Swift,

Para ello estoy intentando seguir la siguiente pregunta de Stack

https://stackoverflow.com/questions/30574484/displaying-validation-error-on-ios-uitextfield-similar-to-androids-textview-set

En unas de sus respuestas encontre la siguiente solucion

    private var rightViews = NSMapTable<UITextField, UIView>(keyOptions: NSPointerFunctions.Options.weakMemory, valueOptions: NSPointerFunctions.Options.strongMemory) private var errorViews = NSMapTable<UITextField, UIView>(keyOptions: NSPointerFunctions.Options.weakMemory, valueOptions: NSPointerFunctions.Options.strongMemory)  extension UITextField {     // Add/remove error message     func setError(_ string: String? = nil, show: Bool = true) {         if let rightView = rightView, rightView.tag != 999 {             rightViews.setObject(rightView, forKey: self)         }            // Remove message         guard string != nil else {             if let rightView = rightViews.object(forKey: self) {                 self.rightView = rightView                 rightViews.removeObject(forKey: self)             } else {                 self.rightView = nil             }              if let errorView = errorViews.object(forKey: self) {                 errorView.isHidden = true                 errorViews.removeObject(forKey: self)             }              return         }          // Create container         let container = UIView()         container.translatesAutoresizingMaskIntoConstraints = false          // Create triangle         let triagle = TriangleTop()         triagle.backgroundColor = .clear         triagle.translatesAutoresizingMaskIntoConstraints = false         container.addSubview(triagle)          // Create red line         let line = UIView()         line.backgroundColor = .red         line.translatesAutoresizingMaskIntoConstraints = false         container.addSubview(line)          // Create message         let label = UILabel()         label.text = string         label.textColor = .white         label.numberOfLines = 0         label.font = UIFont.systemFont(ofSize: 15)         label.backgroundColor = .black         label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 250), for: .horizontal)         label.translatesAutoresizingMaskIntoConstraints = false         container.addSubview(label)          // Set constraints for triangle         triagle.heightAnchor.constraint(equalToConstant: 10).isActive = true         triagle.widthAnchor.constraint(equalToConstant: 15).isActive = true         triagle.topAnchor.constraint(equalTo: container.topAnchor, constant: -10).isActive = true         triagle.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: -15).isActive = true          // Set constraints for line         line.heightAnchor.constraint(equalToConstant: 3).isActive = true         line.topAnchor.constraint(equalTo: triagle.bottomAnchor, constant: 0).isActive = true         line.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 0).isActive = true         line.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: 0).isActive = true          // Set constraints for label         label.topAnchor.constraint(equalTo: line.bottomAnchor, constant: 0).isActive = true         label.bottomAnchor.constraint(equalTo: container.bottomAnchor, constant: 0).isActive = true         label.leadingAnchor.constraint(equalTo: container.leadingAnchor, constant: 0).isActive = true         label.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: 0).isActive = true          if !show {             container.isHidden = true         }         // superview!.superview!.addSubview(container) //        UIApplication.shared.keyWindow!.addSubview(container)         self.addSubview(container)          // Set constraints for container         container.widthAnchor.constraint(lessThanOrEqualTo: superview!.widthAnchor, multiplier: 1).isActive = true         container.trailingAnchor.constraint(equalTo: superview!.trailingAnchor, constant: 0).isActive = true         container.topAnchor.constraint(equalTo: superview!.bottomAnchor, constant: 0).isActive = true          // Hide other error messages         let enumerator = errorViews.objectEnumerator()         while let view = enumerator!.nextObject() as! UIView? {             view.isHidden = true         }          // Add right button to textField         let errorButton = UIButton(type: .custom)         errorButton.tag = 999         errorButton.setImage(UIImage(named: "ic_error"), for: .normal)         errorButton.frame = CGRect(x: 0, y: 0, width: frame.size.height, height: frame.size.height)         errorButton.addTarget(self, action: #selector(errorAction), for: .touchUpInside)         rightView = errorButton         rightViewMode = .always          // Save view with error message         errorViews.setObject(container, forKey: self)     }      // Show error message     @IBAction     func errorAction(_ sender: Any) {         let errorButton = sender as! UIButton         let textField = errorButton.superview as! UITextField          let errorView = errorViews.object(forKey: textField)         if let errorView = errorView {             errorView.isHidden.toggle()         }          let enumerator = errorViews.objectEnumerator()         while let view = enumerator!.nextObject() as! UIView? {             if view != errorView {                 view.isHidden = true             }         }          // Don't hide keyboard after click by icon //                UIViewController.isCatchTappedAround = false     } }  class TriangleTop: UIView {     override init(frame: CGRect) {         super.init(frame: frame)     }      required init?(coder aDecoder: NSCoder) {         super.init(coder: aDecoder)     }      override func draw(_ rect: CGRect) {         guard let context = UIGraphicsGetCurrentContext() else {             return         }          context.beginPath()         context.move(to: CGPoint(x: (rect.maxX / 2.0), y: rect.minY))         context.addLine(to: CGPoint(x: rect.maxX, y: rect.maxY))         context.addLine(to: CGPoint(x: (rect.minX / 2.0), y: rect.maxY))         context.closePath()          context.setFillColor(UIColor.red.cgColor)         context.fillPath()     } } 

El cual es una extension de UITextField el cual arma a codigo un contenedor el cual le mete un triangulo y arma el resto del texto y fondo pero cuando lo va a agregar a la vista veo que realiza

       UIApplication.shared.keyWindow!.addSubview(container) 

Lo cual provoca que lo que muestra mi error se vaya al final de la pantalla quedando inutil

Como se ve en la siguiente imagen introducir la descripción de la imagen aquí

Si agrega el icono en el medio de la caja pero el “conteiner” que contiene el fondo negro con la string de error se va directo al fondo,

Mi pregunta es como yo podria acomodar este codigo para que no se vaya al final sino siempre abajo de mi caja ??

pushViewController no funciona SWIFT

Tengo mi proyecto en MVCP y utilizo un wfm como manejador una foto de mi arbol introducir la descripción de la imagen aquí

Tengo en mi pantalla un metodo el cual me deberia llevar del login al registro — secuencia de eventos

LOGIN

@IBAction func btnGoToRegistro(_ sender: Any) {         self.loginPresenter.goToRegistro()     } 

PresenterLogin

 func goToRegistro(){      self.wfm.goToRegistro() } 

WFM

func goToRegistro(){     self.insecure = self.INSECURE_STR     self.viewController = RegistroViewController.init()     self.viewController?.gesturesEnabled = false     self.viewController?.timeout = false     self.navigationController?.pushViewController(self.viewController!, animated: true)                 } 

El problema es que no pasa a la pantalla de registro, el log de los errores no me marca nada ni se cae la app ni nada simplemente no se mueve a la siguiente pantalla

UIScrollView con UIPageControl no queda centrado correctamente SWIFT

Actualmente estoy necesitando tener un UIPageControl haciendo uso del UIScrollView para poder tener un efecto de carrosuel introducir la descripción de la imagen aquí

Mi problema es que las UIView no quedan centradas cada una un ejemplo mas practico

introducir la descripción de la imagen aquí

Se me queda parte de la segunda vista como parte de la primera

Mis clases son :

class InitialViewController: CommonViewController, UIScrollViewDelegate{  @IBOutlet weak var pageControl: UIPageControl!  @IBOutlet weak var scrollView: UIScrollView!{     didSet{         scrollView.delegate = self     } }   var presenter = InitialPresenter() var slides:[Slide] = [];              override func viewDidLoad() {     super.viewDidLoad()       self.slides = createSlides()     self.setupSlideScrollView(slides: slides)     self.pageControl.numberOfPages = slides.count     self.pageControl.currentPage = 0     self.view.bringSubview(toFront: pageControl) }  override func viewWillAppear(_ animated: Bool) {     super.viewWillAppear(animated)     self.presenter.wfm = WorkflowManager.init(navigationController: self.navigationController) }   func createSlides() -> [Slide] {      let slide1:Slide = Bundle.main.loadNibNamed("ViewSlide", owner: self, options: nil)?.first as! Slide     slide1.imgCenterSlide.image = UIImage(named: "icono_transferencia_carrusel")     slide1.strLblTitle.text = NSLocalizedString("strLblTitleSlideOne_INTIAL",comment:"")     slide1.strLblSubTitle.text = NSLocalizedString("strLblSubTitleSlideOne_INTIAL",comment:"")      let slide2:Slide = Bundle.main.loadNibNamed("ViewSlide", owner: self, options: nil)?.first as! Slide     slide2.imgCenterSlide.image = UIImage(named: "icono_pago_carrusel")     slide2.strLblTitle.text = NSLocalizedString("strLblTitleSlideTwo_INTIAL",comment:"")     slide2.strLblSubTitle.text = NSLocalizedString("strLblSubTitleSlideTwo_INTIAL",comment:"")      let slide3:Slide = Bundle.main.loadNibNamed("ViewSlide", owner: self, options: nil)?.first as! Slide     slide3.imgCenterSlide.image = UIImage(named: "icono_consulta_carrusel")     slide3.strLblTitle.text = NSLocalizedString("strLblTitleSlideTree_INTIAL",comment:"")     slide3.strLblSubTitle.text = NSLocalizedString("strLblSubTitleSlideTree_INTIAL",comment:"")      let slide4:Slide = Bundle.main.loadNibNamed("ViewSlide", owner: self, options: nil)?.first as! Slide     slide4.imgCenterSlide.image = UIImage(named: "icono_simulador_carrusel")     slide4.strLblTitle.text  = NSLocalizedString("strLblTitleSlideFour_INTIAL",comment:"")     slide4.strLblSubTitle.text = NSLocalizedString("strLblSubTitleSlideFour_INTIAL",comment:"")      slide1.strLblTitle.textColor = Utils.Color.BlueLabelText     slide1.strLblSubTitle.textColor = Utils.Color.BlueLabelText      slide2.strLblTitle.textColor = Utils.Color.BlueLabelText     slide2.strLblSubTitle.textColor = Utils.Color.BlueLabelText      slide3.strLblTitle.textColor = Utils.Color.BlueLabelText     slide3.strLblSubTitle.textColor = Utils.Color.BlueLabelText      slide4.strLblTitle.textColor = Utils.Color.BlueLabelText     slide4.strLblSubTitle.textColor = Utils.Color.BlueLabelText         return [slide1, slide2, slide3, slide4] }  func setupSlideScrollView(slides : [Slide]) {     scrollView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)     scrollView.contentSize = CGSize(width: view.frame.width * CGFloat(slides.count), height: view.frame.height)     scrollView.isPagingEnabled = true      for i in 0 ..< slides.count {         slides[i].frame = CGRect(x: view.frame.width * CGFloat(i), y: 0, width: view.frame.width, height: view.frame.height)         scrollView.addSubview(slides[i])     } }  /*  * default function called when view is scolled. In order to enable callback  * when scrollview is scrolled, the below code needs to be called:  * slideScrollView.delegate = self or  */ func scrollViewDidScroll(_ scrollView: UIScrollView) {     let pageIndex = round(scrollView.contentOffset.x/view.frame.width)     pageControl.currentPage = Int(pageIndex)      let maximumHorizontalOffset: CGFloat = scrollView.contentSize.width - scrollView.frame.width     let currentHorizontalOffset: CGFloat = scrollView.contentOffset.x      // vertical     let maximumVerticalOffset: CGFloat = scrollView.contentSize.height - scrollView.frame.height     let currentVerticalOffset: CGFloat = scrollView.contentOffset.y      let percentageHorizontalOffset: CGFloat = currentHorizontalOffset / maximumHorizontalOffset     let percentageVerticalOffset: CGFloat = currentVerticalOffset / maximumVerticalOffset       /*      * below code changes the background color of view on paging the scrollview      */     //        self.scrollView(scrollView, didScrollToPercentageOffset: percentageHorizontalOffset)       /*      * below code scales the imageview on paging the scrollview      */     let percentOffset: CGPoint = CGPoint(x: percentageHorizontalOffset, y: percentageVerticalOffset)   }     func scrollView(_ scrollView: UIScrollView, didScrollToPercentageOffset percentageHorizontalOffset: CGFloat) {     if(pageControl.currentPage == 0) {         //Change background color to toRed: 103/255, fromGreen: 58/255, fromBlue: 183/255, fromAlpha: 1         //Change pageControl selected color to toRed: 103/255, toGreen: 58/255, toBlue: 183/255, fromAlpha: 0.2         //Change pageControl unselected color to toRed: 255/255, toGreen: 255/255, toBlue: 255/255, fromAlpha: 1           pageControl.pageIndicatorTintColor = Utils.Color.BlueLabelText            slides[pageControl.currentPage].backgroundColor = Utils.Color.LigthViewBackGround          let pageSelectedColor: UIColor = fade(fromRed: 81/255, fromGreen: 36/255, fromBlue: 152/255, fromAlpha: 1, toRed: 103/255, toGreen: 58/255, toBlue: 183/255, toAlpha: 1, withPercentage: percentageHorizontalOffset * 3)         pageControl.currentPageIndicatorTintColor = Utils.Color.BlueLabelText     } }   func fade(fromRed: CGFloat,           fromGreen: CGFloat,           fromBlue: CGFloat,           fromAlpha: CGFloat,           toRed: CGFloat,           toGreen: CGFloat,           toBlue: CGFloat,           toAlpha: CGFloat,           withPercentage percentage: CGFloat) -> UIColor {      let red: CGFloat = (toRed - fromRed) * percentage + fromRed     let green: CGFloat = (toGreen - fromGreen) * percentage + fromGreen     let blue: CGFloat = (toBlue - fromBlue) * percentage + fromBlue     let alpha: CGFloat = (toAlpha - fromAlpha) * percentage + fromAlpha      // return the fade colour     return UIColor(red: red, green: green, blue: blue, alpha: alpha) } 

}

Mi clase Slide es la siguiente

class Slide: UIView {   @IBOutlet weak var strLblTitle: UITextView!  @IBOutlet weak var imgCenterSlide: UIImageView!  @IBOutlet weak var strLblSubTitle: UITextView! @IBOutlet weak var viewBackGround: UIView! 

}

y mis contrainsts son

introducir la descripción de la imagen aquí

introducir la descripción de la imagen aquí

Desde ya cualquuier ayuda es bienvenida no entiendo porque no puede quedar cada view centrado