NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

=>1)coredata
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
1)NavigationController(Object Libery)
2)Change Entry point viewcontroller to navigation controller
3)Drag button and add to top of the tableview navigation (middle one)
4)create segue to tableview to viewcontroller(select show)
5)add labels(in tableview)(show details)
6)in viewcontroller add label and textfield (to add details)
7)craete file NoteCell.swift(this file contain the label name in tableview)
8)craete file NoteTableView.swift(this file contain all tableview function operation)
9)Change the viewController name to NoteDetailVC.swift
10)In StoryBoard Change all classname
i)viewcontroller -> NoteDetailVC
ii)Middle Navigation change to ->NoteTableview
iii)inside of that change Tableviewcell to -> NoteCell

11)add button on viewcontroller (NoteDetailVC) in add Savebutton


add Entity
1)Note
i)id - Integer32
ii)title -String
iii)desc-String
iv)deleteddate-Date

12)in coredata open left panel to change codegen -> Manual/None

13)Create Note.swift file to add all attribute in that

i)Note.Swift
-----------------
import CoreData
@objc(Movie)

class Movie :NSManagedObject
{
@NSManaged var id:NSNumber!
@NSManaged var moviename:String!
@NSManaged var desc:String!
@NSManaged var deletedData:Date?
}
============================================================================

ii)NoteCell.swift //to decalre what to show on tableview that declare here
------------------
import UIKit

class MovieCell:UITableViewCell{

@IBOutlet weak var MovieLabel: UILabel!

@IBOutlet weak var DescriptionLabel: UILabel!
}
=============================================================================

iii)NoteTableView.swift
-----------------------
import UIKit
import CoreData

var MovieList = [Movie]()

class MovieTableview:UITableViewController{

var firstLoad = true

override func viewDidLoad() {
if(firstLoad)
{
firstLoad=false
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context:NSManagedObjectContext = appDelegate.persistentContainer.viewContext
let request=NSFetchRequest<NSFetchRequestResult>(entityName: "Movie")
do{
let results:NSArray = try context.fetch(request)as NSArray
for result in results {
let Movie = result as! Movie
MovieList.append(Movie)
}
}
catch{
print("Fetch Field")
}
}
}
//Copy MovieCellId to the MainStoryboard to click (middle Navigation)Tableview->Note Cell ->Change Identifier to "MovieCellID"
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let MovieCell = tableView.dequeueReusableCell(withIdentifier:"MovieCellID", for:indexPath) as! MovieCell

let thisMovie: Movie!
thisMovie = MovieList[indexPath.row]

MovieCell.MovieLabel.text = thisMovie.moviename
MovieCell.DescriptionLabel.text = thisMovie.desc
return MovieCell
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return MovieList.count
}

override func viewDidAppear(_ animated: Bool) {
tableView.reloadData()
}

//for "editMovie" To change Identifier in the segue add one more Middle to viewcontroller and set select "show"
//for "newMovie" to change Identifier in the segue first
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "editMovie", sender: self)

}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier=="editMovie")
{
let indexPath = tableView.indexPathForSelectedRow!
let MovieDetail = segue.destination as? MovieDetailVC
let selectedMovie:Movie!
selectedMovie=MovieList[indexPath.row]
MovieDetail!.selectedMovie = selectedMovie


}
}
}
=============================================================================

iv)NoteDetailVC.Swift(ViewController)
----------------------
import UIKit
import CoreData
class MovieDetailVC: UIViewController {


@IBOutlet weak var MovieName: UITextField!
@IBOutlet weak var Description: UITextView!

var selectedMovie: Movie? = nil

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if(selectedMovie != nil)
{
MovieName.text=selectedMovie?.moviename
Description.text=selectedMovie?.desc
}
}


@IBAction func SaveAction(_ sender: Any) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context:NSManagedObjectContext = appDelegate.persistentContainer.viewContext
let entity = NSEntityDescription.entity(forEntityName:"Movie", in:context)
let newMovie = Movie(entity:entity!,insertInto:context)
newMovie.id = MovieList.count as NSNumber
newMovie.moviename = MovieName.text
newMovie.desc = Description.text
do{
try context.save()
MovieList.append(newMovie)
navigationController?.popViewController(animated: true)
}
catch{
print("context save error")
}
}

}

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=>2)quiz app

class ViewController: UIViewController {
@IBOutlet var questionLabel: UILabel!
@IBOutlet var answerLabel: UILabel!

let questions : [String]=["","",""]
let answers:[String]=["","",""]

var currentQuestionIndex : Int = 0

@IBAction func showNextQuestion(_ sender: UIButton) {
currentquestionIndex +=1
if currentquestionIndex == questions.count
{ currentquestionIndex = 0 }
let question : String = questions[currentquestionIndex]
questionLabel.text = question
answerLabel.text = "???"
}
@IBAction func showAnswer(_ sender: UIButton) {
let answer : String =answers[currentQuestionINdex]
answerLabel.text=answer
}
override func viewDidLoad()
{
super.viewDidLoad()
questionLabel.text= questions[currentquestionIndex]
}
}
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=>3)TableView(Add,View)

i)ViewController

@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var lbl: UILabel!

var names = ["","",""]

override func viewDidLoad() {
super.viewDidLoad()
lbl.text = "Bags"
}

extension ViewController: UITableViewDelegate, UITableViewDataSource {

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? CellTableViewCell
cell?.lbl.text = names[indexPath.row]
cell?.img.image = UIImage(named: names[indexPath.row] )
return cell!
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
120
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = storyboard?.instantiateViewController(withIdentifier: "DetailViewController") as? DetailViewController
vc?.image = UIImage(named: names[indexPath.row] )!
vc?.name = names[indexPath.row]
navigationController?.pushViewController(vc!, animated: true)
}
}

ii)DetailsDesignviewController.swift

@IBOutlet weak var lbl: UILabel!
@IBOutlet weak var img: UIImageView!

var image = UIImage()
var name = ""

override func viewDidLoad() {
super.viewDidLoad()
lbl.text = "You selected (name) for vote"
img.image = image
}

embed in Navigation Controller in First Screen (to add Tableview)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
3)Collection View(images and text)

-Add all images in Assert.xcasserts(1x)
-collection view (object Libery)
-select collectionview press ctrl drag to viewcontroller and set Datasource,delegate
-inside Collectionview ->select collectionview cell
-object libery drag and drop Image,text filed
-change name Collectionview cell to -> cell (Identifier name change)
-craete file (cocoa Touch class) name->CollectionViewCell subclass UiCollectionViewCell
-set that class file to cell ->chnage class to MycollectionViewCell
-open viewcontroller(assist)
-select Collection view to ctrl and drag to view controller to create Outlet

i)ViewController.swift
----------------------
@IBoutlet var mycollectionview:UICollectionView!

let productTypeName:[String]=["","",""] //all name to display in textfiled
let productImages:[String]=["","",""] //all name to display in imagefild

class end

extension ViewController : UICollectionviewDelegate , UICollectionViewDatasource,UiCollectionViewDelegateFlowLayout
{

numberofIteminsection
{
return productTypeName.count

}

cellForItemAt
{
let cell=myCollectionView.dequeueReusableCell(withReuseIdentifier:"cell",for:indexpath) as! MycollectionViewCell
cell.myImage.image = UIImage(named:productImages[indexpath.row])
cell.myLabel.text= productTypeName[index.path]
cell.layer.cornerRadius=10
cell.layer.borderWidth=1
cell.layer.borderColor = UIColor.blue.cgColor
return cell

}

sizeForItemAt
{
let size = (collectionView.frame.size.width-10/2)
return CGSize(width : size , height : size)

}

}

ii)MyCollectionViewcell.swift
-----------------------------
@IbOutlet var myImage:UIImageView!
@Iboutlet var myLabel:UILabel!


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=>4)Keyboard hide

func textFieldShouldReturn(_textField:UITextField)->Bool{
textField.resignFirstResponder()
return true
}

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=>5)cocoapods

<?php

$con=mysqli_connect(”localhost”,”root”,”root”,”mydb”);

$sql=select*from studentdetails;

$rows=array();//declare array

if($result=mysqli_query($con,$sql))

{

while($row=mysqli_fetch_assoc($result))

{

array_push($rows,row);

}

print json_encode($rows);

mysqli_free_result($result);

}

mysqli_close($con);

?>

Cocoapods (code)

---

(cocoapods built with ruby,install cocoapods in mac use this command)

$sudo gem install cocoapods

$pod setup —verbose

Create new project Use this command to install dependencies

→$pod init

→$open -a xcode podfile

→$pod install

→$open cocoapods1.xcworkspace //open project in xcode

(code of cocoapods)

import UIkit

import Alamofire //dependencies of pods

class viewcontroller:UIviewcontroller

{

override func viewDidload()

{

guard let url=URL(string:”http://localhost/studentdetails.php”) else { return }

var request = URLRequest(Url : url)

request.httpMethod=”GET”

request.addvalue(”application/json”,forHttpHeaderField:”content-type”)

Alamofire.request(request).responseJSON()

{

response in

switch response.result

{

case .success(let data):

print (”successfully”,data);

case .failure(let error):

print (”request fail (error)”)

}

}

}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.