Author Topic: String Literals?  (Read 606 times)

Sam

  • Newbie
  • *
  • Posts: 9
    • View Profile
String Literals?
« on: April 08, 2018, 03:42:44 PM »
In Book 3, page 345, the code to enter says, 

      "let shipmentEntity =
         self.shipmentList[indexPath.row]
      cell.textLabel?.text = shipmentEntity.name
      cell.detailTextLabel?.text =
      "\(shipmentEntity.address),
      \(shipmentEntity.city),
      \(shipmentEntity.region),
      \(shipmentEntity.postalCode)"

However, Xcode does not like comma separated shipmentEntity entries and seems to want each entity encapsuled with " ".  While doing so seems to enable the recognition of the individual shipmentEtities, the city, region, and postal code lines all have a warning that say "String literal is unused."

Is there a fix for this?  I don't see anything in Stack Overflow...

thank you!

Sam

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: String Literals?
« Reply #1 on: April 08, 2018, 05:57:32 PM »
getting same error "String literal is unused" for the shipmentEntity  in the DeliveriesViewController

City is showing but no region or postal code

Sam

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: String Literals?
« Reply #2 on: April 08, 2018, 09:50:56 PM »
And not sure if this is related but after updating the Shipment scene to direct the segue for the Delivery Status (pg363 - 365), clicking on the Delivery Status  on the Shipment scene from the simulator is causing the app to crash.

the error shows in the DeliveryStatusViewController:

 override func viewDidLoad() {
        super.viewDidLoad()
      
      //Share the shipment entity object context
      self.deliveryStatus.managedObjectContext = self.shipmentEntity.managedObjectContext!  //Marked as Thread 1: Fatal Error: unexpectedly found nil while unwrapping


However as instructed on page 332, the Shipment Entity optionals were removed.  not sure if this is related to String Literals or a separate problem, although it would seem to be related.

Please advise....

angelina

  • Global Moderator
  • *****
  • Posts: 25
    • View Profile
Re: String Literals?
« Reply #3 on: April 08, 2018, 10:35:19 PM »
Hi Sam,

To answer your first question regarding the string literal issue, try using this code in DeliveriesViewController in the tableView cellForRowAt method.

Code: [Select]
cell.detailTextLabel?.text =
            shipmentEntity.address! + ", " +
            shipmentEntity.city! + ", " +
            shipmentEntity.region! + ", " +
            shipmentEntity.postalCode!


The second issue is unrelated to the first.  To resolve this second issue, make sure that you have the Storyboard Segue Identifier set as "DeliveryStatusSegue" for the segue going from the ShipmentViewController to the DeliveryStatusViewController.



Angelina
Oak Leaf Enterprises, Inc.
« Last Edit: April 08, 2018, 10:46:02 PM by angelina »

Sam

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: String Literals?
« Reply #4 on: April 09, 2018, 09:36:24 AM »
Thank You Angelina,

The + "," + worked!

As for the segue, I had mislabeled the DeliveryStatusSegue.  However, when I renamed it, I am still getting the crash.  I tried deleting the segue and reconnecting the triggered segue with the correct name and double checked that the spelling is right in the ShipmentViewController without success.  This is the error that appears in the console:

libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

in the past I've noticed that this seems to happen when the connections haven't been fully deleted from the code (usually a connection still exists in the Connection Inspector), but that doesn't appear to be the situation this time?

Sam

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: String Literals?
« Reply #5 on: April 09, 2018, 10:17:12 AM »
oh also Im getting a warning that Prototype table cells must have reuse identifiers.  I realized that the segue to the MapView did not have an Identifier so I just deleted the segue.  So now the segue to the Delivery Status works (although the segue to the MapView obviously doesn't).  iDeliverMobileCD doesn't have the MapOptionsViewController or the code associated with the MapView in the ViewController that iDeliverMobile has from the earlier chapter so deleting the segue is of little consequence I assume.

angelina

  • Global Moderator
  • *****
  • Posts: 25
    • View Profile
Re: String Literals?
« Reply #6 on: April 09, 2018, 10:46:54 AM »
The warning that Prototype table cells must have a reuse identifier means that each prototype cell must have an Identifier (name) assigned to it.  This Identifier must also match the identifier listed in the tableView cellForRowAt method.  You can add the Identifier by clicking the cell and in the Attributes Inspector in the Table View Cell section, make sure that the Identifier field has a value assigned to it.  For example, in the ShipmentViewController, if I click the PhoneCell and go to the Attributes Inspector, I can see that the Identifier says, "PhoneCell".

The Storyboard Segue Identifier and the Table View Cell Identifier are two different things even though the word "Identifier" can be a little confusing.  You can put the segue between the ShipmentViewController and the MapView back.


Angelina
Oak Leaf Enterprises, Inc.

Sam

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: String Literals?
« Reply #7 on: April 09, 2018, 11:39:47 PM »
Thank you Angelina,
  Yes I think I got the distinctions between the Identifiers fine.  I'll reconnect the segue to the MapView and see if it's working again.  What I know for sure was when that with the original segue connected to the MapView, the segue to the Delivery Status consistently crashed!

Sam

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: String Literals?
« Reply #8 on: April 10, 2018, 08:24:47 PM »
reconnected the segue from the address to the MapView and segueing no problem! thank you!

angelina

  • Global Moderator
  • *****
  • Posts: 25
    • View Profile
Re: String Literals?
« Reply #9 on: April 11, 2018, 04:30:51 PM »
You're welcome :)  I'm glad it worked!


Angelina
Oak Leaf Enterprises, Inc.