How to store and retrieve data from an optional array of integers using core-data? - xcode

I've developed an iPhone app that is working fine except for navigating from one view to another without losing the data. I know that core-data is the solution but I'm a beginner in this area. I need to store and retrieve several arrays such as: var arrayName = [Int?] (repeating: nil, count: 9) in the exact order they become populated (0-8). How do I set these existing arrays up in core-data?
I've watched and read several tutorials, but none explain how to include an array (especially with integers) that already exists.
All of my code is working perfectly for this app. I only need to save the data.
I expect to be able to navigate from view to view and return with everything in place. Also to close and reopen the app where I left off.
Note: No need for error messages.

Related

Validate single record on continuous form

So I have a form and a table called Variables. The table is simply the fields VarID, VarDescription, and VarValue. It's only three items that are all network locations of things. The VarValue is the only thing that can be changed through the form, and thus it is the only thing validated. I validate those records on the form with the Before Update Event in the control by using logic such as:
If Me.VarID = 1 Then
If Me.Tex like "*:\* Then....
End If
If GetAttr(Me.Tex) = vbDirectory Then
End
End If
If Me.VarID = 2 Then
If Me.Tex like "*:\* Then....
End If
If GetAttr(Me.Tex) = vbNormal Or GetAttr(Me.Tex) = vbArchive Then
End If
End If
This all works great. However my issue comes in when multiple locations become invalid at once. I get stuck in one cell because the other VarValue's are invalid as well. How can I validate only the cell I have changed? I tried playing around with various Dirty and Focus events/methods, but those seem to be form specific, not cell specific.
This seems to just be a reference issue as I am looking on the database on two completely separate networks. The original uses all Office 16.0 libraries whereas the instance I was having the issue with was using Office 15.0 libraries. I played around with the original and it works fine, even if all the locations become bad at the same time.

swift : display info to a users (first use) and then disappear

I would like to display some info on the screen ... which will disappear.
Example : an Uiview is displayed for the first time to an user (or feature never used by the user). I would like to display on a screen a label or an image to explain how to use this new feature. After that it will disappear ...
If this functionality has already been used by the user, the message is ofcourse not displayed.
example of message --> to add a gamer, press +
How to do that ? a lot of apps have this kind of help.
thanks
What you have to do is actually very simple : have a persistent variable, and change its value. Each time the user could see the help popup, you check the value of the variable you stored persistently. If this variable indicates that the user have already seen the help, you don't display it again. Otherwise, you show it. Simple example:
let helpSeen: Bool = getVarFromPersistent()
if helpSeen == false {
// DISPLAY THE HELP MESSAGE OR POPUP
setHelpSeenVar(true)
}
Where getVarFromPersistent() and setHelpSeenVar() are function you could create to respectively retrieve the variable from the persistent data and set the variable in the persistent data.
Now, you have to figure out how to use persistent data. You can have a look at CoreData, that is provided by Apple and "ready to use" in Xcode. You've probably already seen the use core data tickbox when you create a project.
Third party libraries exists as well like RealmSwift, who reached version 1.0 recently.
I'm not an expert, but I think Realm is simpler to use than Core Data. The technology used by the two libraries could be different though, maybe someone else could tell you more about it. Anyway, you will find a lot of article about Realm and Core Data on Google.

Unity Session Login

I have a login validation where the users will enter their identity card number in unity. In the database, the identity card number is linked to several information. What I want to do is to create a session in the login page where the identity card number will be stored in a string or object and it can be retrieved in another page to call out for the information in the database. However, I have been looking around for solutions that would be able to work on the unity engine but unable to find any. Would be great is anyone can help me with this, thanks!
Few options to access variables across multiple scenes:
Use static variables, they keep values between scenes : (basic example) http://answers.unity3d.com/questions/41891/static-variables-between-scenes.html
Look up singletons : http://wiki.unity3d.com/index.php/Singleton (bit complex example, there are simpler ones in unity forums.. Looks like that Toolbox global variable is similar : http://wiki.unity3d.com/index.php/Toolbox )
(Simple solution) Save&Load values with PlayerPrefs : http://docs.unity3d.com/ScriptReference/PlayerPrefs.html
Set your script as DontDestroyOnLoad, so it doesnt get deleted when going to another scene : http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html (but be careful when entering the same scene, your object gets instantiated again if you dont check it)

What is the relationship between CGPDFContext and CGPDFDocument?

My understanding of this was that perhaps CGPDFContext is to be used for editing PDF document data and CGPDFDocument is used for storing it, since the documentation doesn't list any ways to alter the content of a CGPDFDocument.
I'm also not quite sure what CGDataConsumer/Provider does. From reading the documentation I got the impression that the consumer/provider abstracts the relationship between the CG object and the CFData it writes to; so I don't have to do that myself. So I figured the following code would create a two page blank PDFdocument:
//Don't know exactly how large a PDF is so I gave it 1 MB for now
self->pdfData = CFDataCreateMutable(kCFAllocatorDefault, 1024);
self->consumerRef = CGDataConsumerCreateWithCFData(self->pdfData);
self.pdfRef = CGPDFContextCreate(self->consumerRef, NULL, NULL);
CGPDFContextBeginPage(self.pdfRef, NULL); //Creates a blank page?
CGPDFContextEndPage(self.pdfRef);
CGPDFContextBeginPage(self.pdfRef, NULL); //Creates a second blank page?
CGPDFContextEndPage(self.pdfRef);
//Copies the data from pdfRef's consumer into docRef's provider?
self.docRef = CGPDFDocumentCreateWithProvider(
CGDataProviderCreateWithCFData(
CFDataCreateCopy(kCFAllocatorDefault, self->pdfData)
));
It didn't work though, and NSLogging the first two pages of docRef returns NULL. I'm rather new at this, the C-Layer stuff in particular. Can someone explain to me the relationship between CGPDFContext, CGPDFDocument, CGDataConsumer & CGDataProvider and how I'd use them to create a blank PDF?
Your basic understanding is correct as far as I can see:
A CGPDFContext is a drawing context that "translates" everything that is drawn onto it to PDF instructions (typically for storage in a PDF file).
A CGPDFDocument is used to open an existing PDF file and get information from it.
When you want to create your own PDF file, you have two ways to do it as described here: https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CGPDFContext/Reference/reference.html
Use "CGPDFContextCreate" which you pass a data consumer. The data consumer gets the data and can do with it as it pleases (you could create a data consumer that passes the PDF onto the clipboard for example).
Use "CGPDFContextCreateWithURL" which you pass a URL. In that case your data will be written to a PDF file at that URL.
If you want to use these functions, have a look at this page https://developer.apple.com/library/mac/documentation/graphicsimaging/Conceptual/drawingwithquartz2d/dq_pdf/dq_pdf.html#//apple_ref/doc/uid/TP30001066-CH214-TPXREF101 which explains in detail how to create PDF files with a data provider and without (simply to a PDF).
To figure out what is happening I would start by trying to write a simple PDF file to disk before writing one to a data provider and then using that data provider immediately to read it again. Without trying your code however, let me point out that you didn't use "CGPDFContextClose" which is described in the document as closing the PDF document and flushing all information to output. You could actually having a situation where stuff is cached and not written to your data provider yet, simply because you haven't forced that.

Magento store view redirects not working in 1.8.0.0

I have a store I'm developing that has two store views, one for each language I'm supporting. The products and categories have localized url keys.
In 1.7.0.2 my language switcher would redirect correctly (for ones that had "Create Permanent Redirect" as well as ones with out) but after upgrading to 1.8.0.0, it did not work any more.
Problem
There is a regression in 1.8.0.0, they updated Mage_Core_Controller_Varien_Front to use ::_getRequestRewriteController() in ::dispatch() previously it used Mage_Core_Model_Url_Rewrite and now it uses Mage_Core_Model_Url_Rewrite_Request
On line 143 of app/code/core/Mage/Core/Model/Url/Rewrite/Request.php it has $stores = $this->_app->getStores(); which returns an array of store_id index stores, but it goes on to check if the store it goes on to check with $fromStore, which is a variable from the GET params, ___from_store, which contains the store views key (e.g. default, french, etc), obviously this has problems looking up using a alpha key in a numericly index array.
Solution
The offending line is again, #143 in app/code/core/Mage/Core/Model/Url/Rewrite/Request.php, by simpling changing it to $stores = $this->_app->getStores(false, true) it will work, as the 2nd parameter being true (defaults to false) returns the array with store view codes as the array key.
Hope this helps someone, and if anyone knows the best way to pass this on to the Magento developers, I would appreciate it, as I said, the issue reporting just posted to the home page, which doesn't seem to work.
Edit: I would also like to point out as 1.8.1.0 this is still an issue.

Resources