Develop the iOS App using the Swift - Part #1

in #utopian-io7 years ago (edited)

New Features

<ul> <li><h2>What feature(s) did you add? <p dir="auto">I am developing steemthink's iOS app and I've got homepage list data. <ul> <li><h2>How did you implement it/them? <p dir="auto">I got the Homepage data from the following three API <pre><code>//GET /get_discussions_by_trending let discussions_by_trending = "https://api.steemjs.com/get_discussions_by_trending?" //GET /get_discussions_by_created let discussions_by_created = "https://api.steemjs.com/get_discussions_by_created?" //GET /get_discussions_by_hot let discussions_by_hot = "https://api.steemjs.com/get_discussions_by_hot?" <p dir="auto">Respectively obtained New, Hot, Trending three modules of data. <p dir="auto">We display the username, post date, title, content, SBD, comments, likes, etc. on the home page. <pre><code>// (Name) nameLab.text = trending?.author // (Date) let timeStr = trending?.last_update.replacingOccurrences(of: "T", with: " ") timeLab.text = NSDate_STExtension.getDateLong(fromDate: timeStr!) // (Title) titleLab.text = trending?.root_title // (Content) contentLab.text = trending?.body // Avatar (Get a list of personal information by authorName)(UserIcon) let url = "https://steemitimages.com/u/"+(trending?.author)!+"/avatar" self.userIconImgV.sd_setImage(with: URL.init(string: url), placeholderImage: UIImage.init(named: "user_icon_placeholder"), completed: nil) let sbd = trending?.pending_payout_value.components(separatedBy: " ").first functionView.dollarLab.text = " " + "\(String(describing: sbd!))" functionView.voteLab.text = String(format: "%d",(trending?.active_votes_arr?.count)!) functionView.commentLab.text = String(format: "%d",(trending?.children)!) <p dir="auto">The avatar is taken separately from the <pre><code>https://steemitimages.com/u/"+(trending?.author)!+"/avatar <p dir="auto">path and it took us quite a while to find this path. <p dir="auto">Earlier we considered obtaining from <pre><code>https://api.steemjs.com/get_accounts?names[]= <p dir="auto">but due to the reusability of cell in iOS development, it is very difficult for us to get the personal information data in cell and then to pull Take the head like address. <ul> <li><h2>This modification of the two most important documents: <li><a href="https://github.com/steemthink/steemthink/blob/3530292fcbd21389ebca075693b70c853ecbe862/iOS/SteemThink/SteemThink/Class/Main/View/Cell/STMainTableViewCell.swift" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">STMainTableViewCell.swift <pre><code>// // STMainTableViewCell.swift // SteemThink // // Created by zhouzhiwei on 2018/2/24. // Copyright © 2018年 zijinph. All rights reserved. // import UIKit import SDWebImage class STMainTableViewCell: STBaseTableViewCell { @IBOutlet weak var userIconImgV: UIImageView! @IBOutlet weak var nameLab: UILabel! @IBOutlet weak var timeLab: UILabel! @IBOutlet weak var titleLab: UILabel! @IBOutlet weak var contentLab: UILabel! @IBOutlet weak var functionView: STMainCellFunctionView! var task:URLSessionTask? var trending:STContent?{ didSet{ //Name nameLab.text = trending?.author // Date let timeStr = trending?.last_update.replacingOccurrences(of: "T", with: " ") timeLab.text = NSDate_STExtension.getDateLong(fromDate: timeStr!) // Title titleLab.text = trending?.root_title // Content contentLab.text = trending?.body // Avatar (Get a list of personal information by authorName)(UserIcon) let url = "https://steemitimages.com/u/"+(trending?.author)!+"/avatar" self.userIconImgV.sd_setImage(with: URL.init(string: url), placeholderImage: UIImage.init(named: "user_icon_placeholder"), completed: nil) let sbd = trending?.pending_payout_value.components(separatedBy: " ").first functionView.dollarLab.text = " " + "\(String(describing: sbd!))" functionView.voteLab.text = String(format: "%d",(trending?.active_votes_arr?.count)!) functionView.commentLab.text = String(format: "%d",(trending?.children)!) } } override func awakeFromNib() { super.awakeFromNib() } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) } func getIconUrl(authorName:String,handler:@escaping (_ iconUrl:String)-> Void) { // Cancel the download task task?.cancel() let author = [authorName] let jsonStr = NSArray_STExtension.getJSONStringFromArray(array:author as [AnyObject]) let url = get_accounts + "names[]=" + jsonStr.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)! task = STAFNetworkTools.sharedTools.requestBack(method: .GET, urlString: url, parameters: nil) { (response: Any?,error: Error?) in if response is NSArray{ for dic:Dictionary in response as! [Dictionary<String, Any>]{ let user:STUser = STUser.init(dict: dic) if let url = user.json_meta?.user_profile?.profile_image { handler(url) }else{ handler("") } break; } } } } } <ul> <li><a href="https://github.com/steemthink/steemthink/blob/cc31d799eb51287256320bc6370207937af2e99c/iOS/SteemThink/SteemThink/Client/STClient.swift" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">STClient.swift <pre><code>// // SteemClient.swift // SteemThink // // Created by zhouzhiwei on 2018/2/22. // Copyright © 2018 zijinph. All rights reserved. // import UIKit let baseURL:String = "https://v2.steemconnect.com" let appId:String = "" //GET /get_discussions_by_trending let discussions_by_trending = "https://api.steemjs.com/get_discussions_by_trending?" //GET /get_discussions_by_created let discussions_by_created = "https://api.steemjs.com/get_discussions_by_created?" //GET /get_discussions_by_hot let discussions_by_hot = "https://api.steemjs.com/get_discussions_by_hot?" //GET /get_accounts let get_accounts = "https://api.steemjs.com/get_accounts?" class STClient: NSObject { typealias STClientCallBack = (_ response: Any?,_ error: Error?)->() func post(url:String,body:Dictionary<String, Any>?,cb:String?) -> Void { let client = STAFNetworkTools.sharedTools; // Set the requested encoding type client.requestSerializer.setValue("", forHTTPHeaderField: "") // var url:String = baseURL // var r = (new Date).toISOString().replace(/[^a-zA-Z0-9]+/g, "").toLowerCase(); // return e = e.replace(/(-\d{8}t\d{9}z)/g, ""), "re-" + t + "-" + e + "-" + r } class func get(url:String!,parameters:AnyObject?,to:UIView?,finished:@escaping STClientCallBack){ STAFNetworkTools.sharedTools.request(method: .GET, urlString: url, parameters: parameters) { (response: Any?,error: Error?) in finished(response,error) } } } <p dir="auto"><br /><hr /><em>Posted on <a href="https://utopian.io/utopian-io/@steemthinkcom/develop-the-ios-app-using-the-swift-part-1" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Utopian.io - Rewarding Open Source Contributors<hr /><p>
Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Hey @codingdefined, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Upvoted ☝ Have a great day!

thanks~

Hey @steemthinkcom I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • This is your first accepted contribution here in Utopian. Welcome!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x