How to debug writing or reading a file

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 489
Joined: Thu Sep 04, 2008 6:23 am

How to debug writing or reading a file

Post by jameshale » Tue Apr 29, 2025 10:26 am

Hi,
I am in the process of updating my iOS app and have hit a snag that has me baffled.
Me app writes an reads preference file.
This worked ine in my initial app.
However when building under the latest xcode and LC 10 my app shows no evidence of reading in the prefs.
So the code that previously worked does not seem to now.

My question: how can I check my read and write routines on my iPad to determine if they are at fault?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: How to debug writing or reading a file

Post by richmond62 » Tue Apr 29, 2025 12:07 pm

I would just set up an extremely basic stack to read in a text file and write a text file.

Now if your stack (which you'll have to turn into an iOS executable) is set to write a file called "GUFF": then having supposedly exported the file you can search on your iPad for a file called "GUFF".

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to debug writing or reading a file

Post by Klaus » Tue Apr 29, 2025 12:40 pm

Hi James,

please post your script(s)!
Guessing is just too time consuming. 8)


Best

Klaus

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 489
Joined: Thu Sep 04, 2008 6:23 am

Re: How to debug writing or reading a file

Post by jameshale » Tue Apr 29, 2025 3:15 pm

I realised I can try the remote debugger.
I can set a breakpoint and put the result after each read and write.

Code: Select all

 put specialFolderPath("documents") into thisfolder
   put thisfolder &"/Heartease/Heartease.pref" into preffile
   put the result
   if there is a file preffile then --load prefs
   put the result
and

Code: Select all

 put specialFolderPath("documents") into thisfolder
   put thisfolder &"/Heartease/Heartease.pref" into preffile
   put prefs into URL("file:/" & preffile)
   put the result

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to debug writing or reading a file

Post by Klaus » Tue Apr 29, 2025 3:33 pm

And what does THE RESULT tell you/us?

Hint:
put prefs into URL("file:/" & preffile)
I think the SLASH is not neccessary:
put prefs into URL("file:" & preffile)

And of course the folder "Heartease" needs to be present to make this work.

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 489
Joined: Thu Sep 04, 2008 6:23 am

Re: How to debug writing or reading a file

Post by jameshale » Thu May 01, 2025 8:21 am

Well removed “/“, thanks @klaus.
Tested in IDE and the simulator and it worked fine.
Tested on my iPad and it fails.

The save file returns “can’t open file”

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How to debug writing or reading a file

Post by Klaus » Thu May 01, 2025 3:56 pm

Just to be sure, the folder "Heartease" already exists on your iPad, right?

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 489
Joined: Thu Sep 04, 2008 6:23 am

Re: How to debug writing or reading a file

Post by jameshale » Fri May 02, 2025 1:30 am

When I open the app, the first thing it does is check for the presence of a pref file.
if it doesn't exist it creates one.
Well it creates the folder and then the file.
This works.
There is indeed a pref file.

jameshale
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 489
Joined: Thu Sep 04, 2008 6:23 am

Re: How to debug writing or reading a file

Post by jameshale » Fri May 02, 2025 6:41 am

So, the left hand doesn't know what the right hand has done.
In updating the app I decided to change the names of the pref file from what had had previously used.
Unfortunately I missed an occurrence.
Sorry :oops:

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: How to debug writing or reading a file

Post by dunbarx » Fri May 02, 2025 4:23 pm

You are forgiven. I don't have to deal with such things, because I never make misteaks.

Craig

Post Reply