https://drive.google.com/file/d/1ybxid8ySCkthtX3hSF3jCbRModW2_q2y/view?usp=sharing
IOS-DEVELOPER
HI THIS IS BLOG TO SHOW EXAMPLE THEORY FOR IOS LEARNER
Thursday, 19 August 2021
Tuesday, 16 July 2019
What is the difference between protocol, extension and category in IOS development? And how to use them appropriately?
Protocols
A protocol declares a programmatic interface that any class may choose to implement.
A protocol defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. Protocols are like Interfaces, that provide some methods that the class conforming must implement.
Uses:
A common use case is to let you alter the behavior of certain classes without the need to subclass them.
Eg: UITableViewDelegate, UITableViewDataSource
Extension
Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for which you do not have access to the original source code (known as retroactive modeling).
Extensions are similar to categories in Objective-C. (Unlike Objective-C categories, Swift extensions do not have names.)
Uses:
Categories are a way to modularize a class by spreading its implementation over many files. Extensions provide similar functionality.
One of the most common uses of categories is to add methods to built-in data types like NSString or NSArray. The advantage of this is that you don’t have to update the existing code to use a new subclass
Thursday, 4 July 2019
IOS APP DATABASE INTEGRATION USING FMDB
STEP ONE CREATE DATABASE AND TABLE
COPY DATA BASE INTO PROJECT
COPY DATA BASE INTO PROJECT
// util.copydataBase("Sata.db") Write this Line IN APPdelegate file after Downloading Zip File and copy into your project
https://drive.google.com/file/d/1nptZ8mE6jc-iCC-EjEtqu5NSVHfAm0SE/view?usp=sharing
Set Below code in your viewcontroller where you want to save data
@IBAction func SaveClick(_ sender: UIButton)
{
let modelinfo = SignuModel(fname: txtFname.text!, lname: txtLname.text!, dob: txtDOB.text!, email: txtEmail.text!)
let isSave = DBHelper.getinstance().savedata(modelinfo)
print(isSave)
}
Monday, 17 June 2019
Service Call With NsUrlSession
func loginWS(parameters:[String:String], completionHandler: @escaping (Any?) -> Swift.Void) {
guard let gitUrl = URL(string: BASE_URL+ACTION_URL) else { return }
print(gitUrl)
let request = NSMutableURLRequest(url: gitUrl)
// uncomment this and add auth token, if your project needs.
// let config = URLSessionConfiguration.default
// let authString = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxMywiUGFzc3dvcmQiOiIkMmEkMTAkYVhpVm9wU3JSLjBPYmdMMUk2RU5zdU9LQzlFR0ZqNzEzay5ta1pDcENpMTI3MG1VLzR3SUsiLCJpYXQiOjE1MTczOTc5MjV9.JaSh3FvpAxFxbq8z_aZ_4OhrWO-ytBQNu6A-Fw4pZBY"
// config.httpAdditionalHeaders = ["Authorization" : authString]
let session = URLSession.shared
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
request.httpBody = try! JSONSerialization.data(withJSONObject: parameters, options: [])
let task = session.dataTask(with: request as URLRequest) { data, response, error in
guard let data = data else { return }
do {
// let decoder = JSONDecoder()
// here replace LoginData with your codable structure.
let gitData = try JSONDecoder().decode(LoginData.self, from: data)
print("response data:", gitData)
completionHandler(gitData)
} catch let err {
print("Err", err)
}
}.resume()
}
Height Label Swift
extension UILabel
{
// SwifterSwift: Initialize a UILabel with text
public convenience init(text: String?)
{
self.init()
self.text = text
}
// SwifterSwift: Required height for a label
public var requiredHeight: CGFloat
{
let label = UILabel(frame: CGRect(x: 0, y: 0, width: frame.width, height: CGFloat.greatestFiniteMagnitude))
label.numberOfLines = 0
label.lineBreakMode = NSLineBreakMode.byWordWrapping
label.font = font
label.text = text
label.attributedText = attributedText
label.sizeToFit()
return label.frame.height
}
// SwifterSwift: Required height for a label
public var requiredWidth: CGFloat
{
let label = UILabel(frame: CGRect(x: 0, y: 0, width: CGFloat.greatestFiniteMagnitude, height: frame.height))
label.numberOfLines = 0
label.lineBreakMode = NSLineBreakMode.byWordWrapping
label.font = font
label.text = text
label.attributedText = attributedText
label.sizeToFit()
return label.frame.width
}
func halfTextColorChange (fullText : String , changeText : String)
{
let strNumber: NSString = fullText as NSString
let range = (strNumber).range(of: changeText)
let attribute = NSMutableAttributedString.init(string: fullText)
attribute.addAttribute(NSAttributedString.Key.foregroundColor, value: Theme.redColor , range: range)
self.attributedText = attribute
}
}
/*
let TotalHeight : Int = Int(cell.lblComment.requiredHeight)
return CGFloat(51+TotalHeight)
*/
Sunday, 9 June 2019
Pagination Using Swift Language 4.0 Scroll and Tableview
var isDataLoading:Bool=false
var pageNo:Int=0
var limit:Int=20
var offset:Int=0 //pageNo*limit
var didEndReached:Bool=false
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
print("scrollViewWillBeginDragging")
isDataLoading = false
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
print("scrollViewDidEndDecelerating")
}
//Pagination
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
print("scrollViewDidEndDragging")
if ((tableView.contentOffset.y + tableView.frame.size.height) >= tableView.contentSize.height)
{
if !isDataLoading{
isDataLoading = true
self.pageNo=self.pageNo+1
self.limit=self.limit+10
self.offset=self.limit * self.pageNo
loadCallLogData(offset: self.offset, limit: self.limit)
}
}
}
Subscribe to:
Posts (Atom)