Post not yet marked as solved
Hello Devs!! Hello from NY o/
On this particular case, I'm make some studying about Dependency Injection and I'm just making a couple mockups to improve my lessons.
By the way, I would like understand more deep why the ...{ coder in ... at my closure be represented a casting with my another class as something like this below:
...
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Movie"
}
@IBAction func inject(_ sender: Any) {
let movie = Movie(title: "GoldenEye 007", genre: "Action", poster: imageLiteral(resourceName: "007 Goldeneye"))
guard let moviesDetailsVC = self.storyboard?.instantiateViewController(identifier: "ShowMore", creator: { coder in
return MoviewsDetailViewController(coder: coder, movie: movie)
}) else {
fatalError("MoviesViewController has not been implemented")
}
self.navigationController?.pushViewController(moviesDetailsVC, animated: true)
}
}
...
That's my another class:
import UIKit
class MoviewsDetailViewController: UIViewController {
@IBOutlet weak var posterImageView: UIImageView!
var movie: Movie
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.title = movie.title
self.posterImageView.image = movie.poster
}
init?(coder: NSCoder, movie: Movie) {
self.movie = movie
super.init(coder: coder)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Cheers!!!
Hello from NY o/
On the many projects, I was working out with Storyboards.
From now on, I'm beginning with View Code and I'm trying to change the size of the UIView as something like that: e.g
class ViewController: UIViewController {
// MARK: - Subviews
private lazy var containerView: UIView = {
let view = UIView()
view.backgroundColor = UIColor.green
view.frame.size.height = 200.0
view.frame.size.width = 300.0
view.sizeToFit()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
view.addSubview(containerView)
containerView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
containerView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}
}
And the size of the View is not sizing. I need use CGRect to change the size of the UIView? But how to center with auto layout when CGRect(x: 0, y: 0, height: 200, width: 350)?
The x & y stay to hard to keep center x & center y at any screen size?
Thanks a lot for you help.
Cheers.
Post not yet marked as solved
Hello, Devs!
On the last years with my team, were are using Storyboards.
From now on we get started with View Code.
I was writing the and learning the best way to do that and I have some doubts around it.
In particular case I writing something like that (Is not done from while)
import UIKit
class TopView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setupTopView()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupTopView() {
self.addSubview(contentTopView )
}
let contentTopView: UIView = {
let topView = UIView(frame: CGRect(x: 0, y: 0, width: 80, height: 80))
topView.backgroundColor = .gray
topView.layer.cornerRadius = 12
topView.layer.shadowRadius = 1.0
topView.layer.shadowOpacity = 0.5
topView.layer.shadowColor = UIColor.lightGray.cgColor
topView.layer.shadowOffset = CGSize(width: 0, height: 10)
return topView
}()
}
This is the best way to write View Code? Why I should to use () on the final block of the contentToTopView after the }?
Thanks,
Cheers!!!
Post not yet marked as solved
Hello, Developers.I Need to fetch this API from Marvel Heroes using Swift 5 - MD5 or some type like that.Marvel develper: https://developer.marvel.comAuthentication for Server-Side ApplicationsServer-side applications must pass two parameters in addition to the apikey parameter:ts - a timestamp (or other long string which can change on a request-by-request basis)hash - a md5 digest of the ts parameter, your private key and your public key (e.g. md5(ts+privateKey+publicKey)For example, a user with a public key of "1234" and a private key of "abcd" could construct a valid call as follows:http://gateway.marvel.com/v1/public/comics?ts=1&apikey=1234&hash=ffd275c5130566a2916217b101f26150 (the hash value is the md5 digest of 1abcd1234)And,for a example only - I did it with JavaScript:// Just a part of code...
...
import md5 from 'js-md5';
// Get yours APIs key at https://developer.marvel.com
const PUBLIC_KEY = ''; // your public key
const PRIVATE_KEY = ''; // youur private key
export default function Heroes({ navigation }) {
const [feedHeroes, setFeedHeroes] = useState([]);
useEffect(() => {
async function loadHeroesCharacters() {
const ts = Number(new Date());
const hash = md5.create();
hash.update(ts + PRIVATE_KEY + PUBLIC_KEY);
try {
const response = await fetch(
`https://gateway.marvel.com/v1/public/characters?ts=${ts}&orderBy=name&limit=10&apikey=${PUBLIC_KEY}&hash=${hash.h ex()}`
);
// continue
...From now on, I really need to make the same thing with Swift 5. I need to use URLSession and should not to use a another dependecies (CocoaPods) like Alomofire to fetch this API.But how I use the MD5 - Hashing with Swift 5?Is there somebody who could help me, please?Cheers,Bruno.
Hi, I'm tryna to get a specific value from this API, but I can't. The values that I have been tryna like title, id and overview is nil. Please, help me.my sample code: let task = URLSession.shared.dataTask(with: url!) { (data, response, error) in
if error != nil {
print("error at \(error!.localizedDescription)")
}else{
do {
if let json = try JSONSerialization.jsonObject(with: data!, options: []) as? [String: Any] {
// try to read out a string array
print(json)
if let id = json["id"] as? [String] {
print(id)
}
...
API:["results": <__NSArrayI 0x600000eb0420>({ adult = 0; "backdrop_path" = "/p15fLYp0X04mS8cbHVj7mZ6PBBE.jpg"; "genre_ids" = ( 27 ); id = 474350; "original_language" = en; "original_title" = "It: Chapter Two"; overview = ...if Someone can help! I thanks.Cheers.