XCode copies blank database when doing build - iphone

I've noticed that even though I placed my sqlite3 database in the "resources" folder, and even though I checked the "Copy file" box, when I do a build, XCode creates an empty database toi the application folder it's building...so it's FINDING the database, and OPENING it, but there's nothing IN it, so when I do a sqlite3_prepare_v2, I get a SQLITE_ERROR...
Help! What am I doing wrong?

This tutorial helps you setup an SQL database that will be included with your program:
SQLite To Do Tutorial
That might help you find something you've missed. I'm assuming that since you're getting SQLITE_ERROR you've correctly included the libsqlite3.0.dylib. Are you sure that your database file is valid and was created correctly?

Related

Xcode debugger displays incorrect values for variables

I previously asked a similar question here. This version has simpler example
UPDATED SUMMARY: Xcode is displaying "FAIL" in the debugger variable section for every String. Swift print() statements show correct variable values. All other data types are displaying correctly. How do I get back to a working executable?
Problem: Xcode is displaying incorrect values for variables. Originally this happened with one project. Now, EVERY project, including new projects, have incorrect variable values. Here is a screenshot demonstrating the issue in a new project (forgive my use of ViewDidLoad() as main()..)
Here's what I did: Delete Xcode.app (version 10.0). Download Xcode 10.1 from the App Store. Create a new project. Type in this code, and run.
This same problem occurs in existing projects in Xcode 9.4.1 and Xcode 10.0 -- same behavior as new installation of Xcode 10.1.
Since all versions of Xcode show same problem, I am assuming this problem is not in the Xcode executable, but in some cache or other temp file. I have cleaned my project, restarted Xcode, rebooted, etc. No help.
So my question is: How do I get a clean installation of Xcode? What directories can I delete to get to a working state? I am a novice. I have only test projects that I run in the iOS debugger or on OS X, so I am quite happy re-compiling all of my projects. Is there a complete list of temp files and directories Xcode uses?
Do I have to delete EVERYTHING Xcode has ever written to disk? I'm open to that if no other solution exists.
Thanks for any suggestions on how to proceed or how to gather more info...
I was able to solve this one after a LOT of guesswork.
I agreed with #Martin R that this didn't sound like a cache issue, since the problem persisted after downloading new versions of Xcode. I guessed that only preferences and UserData would out-live the new executable...
I reviewed the UserData directory, and found a subdirectory for the debugger:
~/Library/Developer/Xcode/UserData/Debugger/
In this directory was a file called "CustomDataFormatters". I don't know how the file got created, but here is its contents:
<?xml version="1.0" encoding="UTF-8"?>
<CustomDataFormatters
version = "1.0">
<SummaryFormatters>
<SummaryFormatter
formatString = "FAIL"
type = "Swift.String">
</SummaryFormatter>
</SummaryFormatters>
</CustomDataFormatters>
This file seems to set every string to "FAIL", which is the exact behavior I saw. Additional testing showed me that integers, floats, and other data types were displaying correctly -- it was only String type that was always incorrect.
Deleting this file solved my problem.
If anyone can explain how this file was created, I would appreciate it, but for now, I am able to debug again!
During app debug, I have right clicked on string variables to "copy" data, or "View Value as...". Did I hit some key sequence to create this file during degug?
Did I hit some weird keyboard shortcut while trying for a CMD+B or CMD+R??
Also, I changed the title of this issue to "Xcode debugger displays “FAIL” for all Strings" to help future searches.

Xcode including rogue files

I am currently making an application and have an issue selecting data from an sqlite database. Although this is currently a problem I am enquiring about something else.
On investigating why the I could not select data I was reviewing the files that are on my iphone for the application to ensure the database file did in fact exist however what I have found is that another sqlite file also exists.
I recognise the name of the file as it is a file that I have created in a different project.
I have tried to search for the filename to ensure I have not copied code causing it and I cannot locate that file name in my code at all.
Does anyone know why this file may have appeared in this project?
----- UPDATE -----
Since originally posting this I have come up with a couple of thoughts. iCloud was originally turned on. I have turned this off. I originally copied and pasted code that referenced the other database. I have tried to delete the file but this fails. I have also deleted the app from the iPhone and have found that the folder for the app remains but claims it is empty and has 0 bytes contained within it (the rogue DB is 116 KB). I think this might be related to the iCloud issue. I am going to restore the content and settings as a test.
----- Update ------
After resetting content and settings the file still comes back so unsure what is going on at present.
Goto the Target's Build Phase tab and look in the Copy Bundle Resources section. Most likely, the other sqlite file is in there and being distributed/installed as part of the package.

iPhone File System

The MyProjectName.app should be in the iPhone App structure directory as read-only, but in the project I have to join Test.sqlite and compile it, then I see the Test.sqlite in the MyProjectName.app.
I posted the project to the physical machine and inserted some data without issues. Is this the right way?
When I add the Test.sqlite and data on the iphone simulator, the Test.sqlite didn't appear to have any data. I have tried to copy the Test.sqlite to Documents. And then when I did it again, the data was displayed in the Documents's Test.sqlite. Do I need Test.sqlite to be copied to the Documents? thank you
The resources which are modified at runtime should be part of Documents directory. iPhone application creates a sandbox environment which is signed. If you try to modify any of the bundle resource, it will not allow. It works fine with simulator but not with device.
So, whatever resources are modified should be copied from bundle to documents directory.
Also, when upgrade is available, bundle is replaced with new version. However documents directory does not change. It remains same. If you want to carry any change with upgrade, you can modify data accordingly.
Hope it helps.
Check the Test.sqlite file is it read only or read/write.Change it into read/write.And if there is any lock for the project just uncheck it.

Strange situation give error: "The application bundle does not contain a valid identifier."

Today I experienced a very strange behavior with my XCode (using Version 4.2, iOS 5.0).
I read some another questions, but my problem is diferent and I never before had this issue.
So, XCode gives me the error "The application bundle does not contain a valid identifier." when I'm trying to run my app on a device (in the simulator just simply does nothing).
I'm sure that the project is correctly set, the bundle ID is correct, my certified is also correct..
I already try a lot of different approaches to solution the problem. Then I realized that it just gives the error when I add a folder to the project with the options "Create folder References for any folder added" selected (like the picture).
I have another apps with folders with folder references, and don't get any error..
Resuming: If I add the folder I get the error, If I don't add a folder, the app runs without any problem..
Could someone help me here trying to figure out whats happens (it's driving me mad).
Thanks!
EDIT:
I managed to mend the problem. I was adding a folder called "Resources", changing the folder name stops giving me the error.
But I would like to know/understand why was I getting the error..
Thanks
I managed to mend the problem. I was adding a folder called "Resources", changing the folder name stops giving me the error. But I would like to know/understand why was I getting the error..
Anyway, not a problem anymore..
I'm missing the target name after the icon at the Add to targets. Got lost somewhere?

Core Data No Longer Updating Sqlite Schema

I am using core data for my app and I never had any problems adding or removing columns until recently. But now even if I make changes to my xcdatamodel and generate new and updated entity h/m files, sqlite doesn't seem to be picking up the changes. I actually went over to the documents folder and inspected the create statement for the relevant tables in sqlite3 and I was able to confirm that the columns I added were missing.
I removed and redeployed the app several times to no avail. Is it possible to do something to the app to make it disregard any schema changes being made through xcdatamodel? I guess another thing I should mention is I recently started putting my entire projects folder in CVS so I wonder if something got messed up in the checkin and check out process.
Sorry. I feel like an idiot. A combination of "Reset Content and Settings" on the Simulator and a "Clean All Targets" in xcode seems to have fixed it.