For anyone familiar with the "TableViewSuite" sample code in apple dev center - iphone

In the "sample code" in iOS Dev Center there is a TableViewSuite.
In the first example SimpleTableView the simulator provides a list of time zones by country.
I can not find the list they are pulling from!
it appears to be an array but I can't find the actual words that are coming up on the simulator screen in Xcode.
I've learned about plists and dictionarys and Arrays and simply can't find where the names are coming from.
I found this line:
// Retrieve the array of known time zone names, then sort the array and pass it to the root view controller.
NSArray *timeZones = [NSTimeZone knownTimeZoneNames];
rootViewController.timeZoneNames = [timeZones sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)];
Again, where is it retrieving the information from?
Thanks again.

They're coming from this message:
[NSTimeZone knownTimeZoneNames]
Which is documented as such:
Returns an array of strings listing the IDs of all the time zones known to the system.
So essentially they're predefined somewhere in iOS and the names are simply being queried off the system.

+[NSTimeZone knownTimeZoneNames] gets the list of time zones from the system itself. There is no list in the project.

Related

Sorting is not working correctly

I am saving some files in document directory through my app using custom naming as "file1.format" ,"file2.format" and so on.Later I fetch these files in an Array and printing them in a loop then they are coming in sorted form but the problem arises when I store "file10.format" and so on. After this the result comes is some what unexpected. As after saving 10th file the output comes like
file1.foramt
file10.format
file2.format
.
.
file6.format
file61.format
file7.format
I don't know why sorting take all 1s or 2s on one place as shown above while it is expected that 10 should just comes after 9 not after 1.I used all kind of sorting but the result is coming same all time.
If you want to sort file names "as the Finder does", use localizedStandardCompare. In particular, numbers in the strings are sorted according to their numeric value:
NSArray *files = [NSArray arrayWithObjects:#"file10.format", #"file2.format", #"file1.format", nil];
NSArray *sorted = [files sortedArrayUsingSelector:#selector(localizedStandardCompare:)];
NSLog(#"%#", sorted);
Output:
2012-11-05 11:38:55.474 test77[533:403] (
"file1.format",
"file2.format",
"file10.format"
)
If you want to go with the regular string sorting sequence, then you should consider renaming your files. file00001.format, file00002.format and so on. In that case file00010.format follows file00009.format and file00011.format comes next
It is actually working correctly.
file10.format
Comes before
file2.format
because the character 0 is seen as less than the character . which it's being compared to (both characters are in the same place in their respective file names.
In fact, back in the day, before you young people with your fancy graphical operating systems, this is how the filesystem sorted files too. </old man rant>

Core Data relationship not saved to store

I've got this command line app that iterates through CSV files to create a Core Data SQLite store. At some point I'm building these SPStop objects, which has routes and schedules to-many relationships:
SPRoute *route = (SPRoute*)[self.idTransformer objectForOldID:routeID ofType:#"routes" onContext:self.coreDataController.managedObjectContext];
SPStop *stopObject = (SPStop*)[self.idTransformer objectForOldID:stopID ofType:#"stops" onContext:self.coreDataController.managedObjectContext];
[stopObject addSchedulesObject:scheduleObject];
[stopObject addRoutesObject:route];
[self.coreDataController saveMOC];
If I log my stopObject object (before or after saving; same result), I get the following:
latitude = "45.50909";
longitude = "-73.80914";
name = "Roxboro-Pierrefonds";
routes = (
"0x10480b1b0 <x-coredata://A7B68C47-3F73-4B7E-9971-2B2CC42DB56E/SPRoute/p2>"
);
schedules = (
"0x104833c60 <x-coredata:///SPSchedule/tB5BCE5DC-1B08-4D11-BCBB-82CD9AC42AFF131>"
);
Notice how the routes and schedules object URL formats differ? This must be for a reason, because further down the road when I use the sqlite store and print the same stopObject, my routes set is empty, but the schedules one isn't.
I realize this is very little debugging information but maybe the different URL formats rings a bell for someone? What could I be doing wrong that would cause this?
EDIT: it seems that one SPRoute object can only be assigned to one SPStop at once. I inserted breakpoints at the end of the iteration and had a look a the sqlite every time and I definitely see that as soon as an SPRoute object (that already had been assigned to a previous stop.routes) is assigned to a new SPStop, the previous stop.routes set gets emptied. How can this be?
Well, we had disabled Xcode's inverse relationship's warning which clearly states:
SPStop.routes does not have an inverse; this is an advanced
setting (no object can be in multiple destinations for a specific
relationship)
Which was precisely our issue. We had ditched inverse relationships because Apple states that they're only good for "data integrity". Our store is read-only so we figured we didn't really need them. We learn now that inverse relationships are a little more than just for "data integrity" :P

XMPPRoster example for iphone?

I have looked at the sample code and still not able to figure out some key functionality of the framework without more in depth documentation. Normally there are books about frameworks but it seems like with this framework, you're on your own until it picks up more mainstream usage.
How do I get the roster list? I see that XMPPRosterCoreDataStorage has an NSMutableSet of rosterPopulationSet. Is this the set of XMPPUserCoreDataStorageObjects, i.e., users, that make up a roster?
My way I'm guessing is a hack--get the presence of every user as it's announced, and stash it in an array. Those are the online buddies. Somehow get the entire roster list, and everyone who is not online, is offline.
I figure that there should be an array of XMPPUserCoreDataStorageObjects, i.e., 30 contacts, 30 entries in the XMPPUserCoreDataStorageObjects table?
How would I access this array and how would I tell if they are online or not?
For online status, am I supposed to query something else, b/c it's not encapsulated in XMPPUserCoreDataStorageObjects is it?
I suppose I could use the didReceivePresence or similar methods, but all in all, I want to use the framework and not fight against it.
Appreciate it!
Thanks
Use XMPPRoster extension with either XMPPRosterCoreDataStorage or XMPPRosterMemoryStorage
Take a look at following code. Please note that this is not complete code but should give you an idea.
XMPPRosterMemoryStorage *rosterstorage = [[XMPPRosterMemoryStorage alloc] init];
xmppRoster = [[XMPPRoster alloc] initWithRosterStorage:rosterstorage];
[xmppRoster activate:xmppStream];
[xmppRoster fetchRoster];

How to get the time and date details from pasteboard

when i copy the content in iphone the content is available in the pastebpard ,how do i get the time and date from the pasteboard
By putting a date and time on the pasteboard in the first place?
Your comment fills in some rather critical missing information. I suggest that you edit your question to include the missing information.
(1) if there is a date & time in what is copied, you'll need to detect it and parse it. How you do that is entirely dependent on what is being copied.
(2) If you want the date/time of when the pasteboard was taken, then you would want to look to the UIPasteboard's API. There isn't anything that captures the date of when a pasteboard was created, though.
Now, if you are looking to see if the pasteboard has changed since the last time you looked, use the [changeCount][2].

iPhone: Reading Text From File and UISegmentedControl

First off, I'm a complete beginner.
That said, I thought an ambitious longer-term project/learning experience would be to create an app that displayed daily quotes, like those cheesy day-by-day calendars our grandmothers have in their bathrooms. I want it to have two per day, each one represented by a tab in a UISegmentedControl. That's the long term. Right now I'd be happy with getting a single day's worth of quotes functioning.
Onto the questions:
How can I get text saved in a .txt or .rtf file to be displayed in a UITextView? Preferably without using 'stringWithContentsOfFile,' since Xcode is telling me that's deprecated.
How can I get content from a different file (or maybe a different portion of the same file...?) to be displayed when the user taps the second segment?
If I can get it running so that those two conditions are met and I understand what's going on, I'll consider the day a success. Thanks!
1.
NSError *error = nil;
NSStringEncoding stringEncoding;
NSString *fileText = [NSString stringWithContentsOfFile:#"/path" usedEncoding:&stringEncoding error:&error];
myTextView.text = fileText;
The error and encoding are optional, and you can pass in nil for both. But if you care about the error, or what encoding the file was in they will have useful info in them after the string is created.
2.
Set the valueChanged outlet in Interface Builder to an IBAction on your controller, such as setSegmentValue:. Then, assuming you have an array of quote strings:
- (IBAction)setSegmentValue:(id)sender {
UISegmentedControl *control = (UISegmentedControl*)sender;
NSString *quote = [quotes objectAtIndex:control.selectedSegmentIndex];
myTextView.text = quote;
}
Even though stringWithContentsOfFile: is deprecated, stringWithContentsOfFile:usedEncoding:error: is not. That is the standard method to use for reading from files.
As for the second question, you simply test the state of the segmented control and perform as action based on it. Admittedly this is a high level answer but should get you going.