Ordering of pList Files - iphone

I am reading in a pList file that I created. It has a list of categories in it and it reads in each one and creates a button to represent that category. The names are:
cHelp, cFun, cReading-Class
I would prefer that the order in the plist file is kept. But instead I get cReading-Class first, cHelp second, and cFun last.
In the file they are listed has cHelp, cFun, cReading-Class.
Why does this happen? Is there a way to control the order? Modifing the order in the plist doesn't help.
Thanks for any and all help.

Are you talking about you have a plist file that contains a dictionary of category (which itself is a dictionary)? If it is a dictionary, it should have no order, if it is an NSArray, there should have an order. Double check for that

Related

Insert initial items to Core Data in Swift

I'm new to Swift developing. I made tableView with 16 rows - there are names and prices of every items.
When the user clicks on a row, a new tableView (with static cell) is shown. The user can edit price (I only need price to be mutable) and save it. Then, the original tableView with the new price is shown.
BUT when I stop and load app again there is the original prices.
I found out that I have to use Core Data to storage data permanently. BUT I need the database to be filled with these 16 rows (with the first load after installing) and then let user to change price permanently (or until change it again).
It is possible? And how? Should I use Core Data or is there an easier option?
Pretty much everything suggested to you so far is more complex than it needs to be. You're talking about local data, and a very small amount of it.
The simplest option is to use a plist.
Xcode can help if you create a new file, select Resource as the type and then Property List. Once created it'll contain a dictionary by default, but you can convert that to an array. Add your data, so you have an array of dictionaries with your values for price etc.
Now, this file will be part of the bundle when you run the app, so you can't edit it. You should copy the file by finding it with NSBundle and copying it with NSFileManager into the documents folder.
Once it's there you can use NSArray init?(contentsOfFile path: String) to load the data. Use mutableCopy to create a version you can edit. You can use this array to drive your table view and you can edit the values it contains. Note that with this simple technique the dictionaries in the array will be immutable, so you're probably better off using NSPropertyListSerialization class func propertyListWithData(_ data: NSData, options opt: NSPropertyListReadOptions, format format: UnsafeMutablePointer<NSPropertyListFormat>) throws -> AnyObject with an option of MutableContainersAndLeaves instead.
Once you've edited the array contents you can write it back to disk for next run (with class func dataWithPropertyList(_ plist: AnyObject, format format: NSPropertyListFormat, options opt: NSPropertyListWriteOptions) throws -> NSData)

Talend How To Pass Last Modified File Into TFileInputDelimited?

I have searched all over, and read this post.
But it doesn't seem complete and doesn't work.
The situation: I need to get the last modified file from a directory on the local machine. I then need to pass that file into the fileinputdelimited component.
I currently have:
tfilelist --> iterate --> titeratetoflow --> tsamplerow
-->tflowtoiterate -> tinpufiledelimited ---> tlogrow (just to make sure its pulling the right file)
But it doesn't work. I have configured it. so that titeratetoflow has a column called
"FileName" with "((String)globalMap.get("CURRENT_FILE"))" as the value,
"FileDirectory" with ((String)globalMap.get("CURRENT_FILEDIRECTORY")) as value, and
"FileAndDirectory" with ((String)globalMap.get("CURRENT_FILEPATH")) as value.
The tsamplerow is limited to "1".
The tiflowtoiterate is set so that
"FileNameOnly" is value of "FileName"
"FileDirectoryOnly" is "FileDirectory" and
"FilePathComplete" is "FileAndDirectory"
In the File location field of the tinputfiledelimited, I have "((String)globalMap.get("FilePathComplete"))"
When it runs I get an error saying cannot find file or path. If I cut out the fileinput component and have it send straight to the tlogrow, it shows a single line of blank entry.
Any ideas?
I'm not sure if you've just slightly misconfigured the job here but it seems to work fine for me.
Here's a few screenshots showing my job design:
The only thing I can think of just by looking at your post is that you might have slightly messed up the key value pair combinations in the tFlowToIterate. I tend to find that the default settings there work fine pretty much all of the time and it makes it a little more obvious what it's doing as well.
EDIT: Actually, it looks like you might be using the wrong values in your tIterateToFlow. The tFileList will throw the values for the file paths etc in to the global map but it will preface it with the unique component name. If you hit ctrl+space in the value window it should prompt you with a list of available values (these are also specified in the "Outline" tab of the studio). It typically makes an implicit conversion to String but for this you will need to explicitly convert it so use .toString() instead of (String).
Another way to get last modified file is as below
tFileList(sorted DESC by file modified date) ------> tFixedFlowInput (schema - filename, filenumber) ----->tHashOutput
here in tFixedFlowInput
filename = file(String)globalMap.get("tFileList_1_CURRENT_FILEPATH")+"/"+(String)globalMap.get("tFileList_1_CURRENT_FILE")
filenumber = (Integer)globalMap.get("tFileList_1_NB_FILE")
What above will accomplish is get list of all files in the directory with their number/rank - where the file last modified will have file number =1 and next to that will have 2...and so on.
Now on SubJobOK of above tFileList you can have tHashInput which will read from above tHashOutput and filter only row where filenumber==1 - which means the last modified file.
tHashInput (link to tHashoutput) ---->tFilterRow(filenumber==1)------>tLogRow
One reason why you are getting null is probably you have used globalMap.get("CURRENT_FILEPATH) instead of globalMap.get("tFileList_1_CURRENT_FILEPATH")
The Simple Solution for above problem could be as below:
tFileList(sorted ASC by file modified date)--> tIterateToFlow --> tJava( just to end the subjob).
Then on
subjob ok --> tfileinput ( use (String)globalMap.get("tFileList_1_CURRENT_FILE") or (String)globalMap.get("tFileList_1_CURRENT_FILEPATH") as a file name/file path)
Explanation:
Since tFileList iterates all the files in ASC order, it will always have Latest file name stored in globalMap for the last iteration. The list is only iterated till tIterateToFlow hence after this component (String)globalMap.get("tFileList_1_CURRENT_FILE") will always give the last file name from the iterated list, which is the latest file in out case.
Main Flow :
Component View:

Separate values from array

This string response i am getting from server.
2001,wooza,0420224346,J Wratt ,+61417697070,2013-55-1803-55-54.jpg,No<br />2002,wooza,0420224346,J Wratt ,+61417697070,2013-56-1803-56-17.jpg,No<br />2003,testing,9894698946,ggh hjj,9894598945,2013-11-1811-11-40.jpg,Yes<br />
I separate each record through "br" and stored it in a array.How do i access (2013-55-1803-55-54.jpg) value from array.
You can get through objectAtIndex method.
Alrenatively its better you keep the all the related data of your custom class and storing that in array.
Most of the times you will need more than one value during display. In that case, just get the object from array and show related info through object reference.
Take comma separated strings from an intended element in a different array and use NSPredicate to get the string containing .jpg in it.

how to check how many file names start with certain chars?

I have an iphone app that saves some people's data on a single file. Each filename is represented by the user name plus an incremental number, say "tommy1", "tommy2",... , "tommy32", then "sarah1", "sarah2", and so on.
Is it possible to count how many of them are "tommy"'s and how many are "sarah"'s from within the code ?
thanks
-[NSFileManager contentsOfDirectoryAtPath:error:]
and
-[NSString hasPrefix:]
and perhaps NSCountedSet.

Compare then download

I have a plist in my document folder of the app with one string, an int value. An another plist is on my server with also a string, an int value.
How can i compare the two int value and then do something if one is bigger than the other thanks to all
How about sending along that int value as part of your download url (in a query parameter), and then only download the file if the number is different? Otherwise return a HTTP 304 (content unmodified) response. This is pretty simple to do in PHP at least...
You need to download the contents of the remote plist and compare it to the local one. Then you can 'do something' if it meets the criteria (e.g. if it's bigger).
Use NSURLConnection to download the data.
You can't compare without downloading.