Make phrases enumerable? - enumerable

I am writing a package which needs to make some customized phrases (e.g. a bunch of city names) externally accessible. (like a normal enum with name 'MyEnum', when user types in "MyEnum.", all its enumerated members will pop up to let user choose)
I tried enum a bunch of city names as follows, but of course it didn't work.
public enum City
{
Los Angeles,
Santa Francisco,
Houston,
New York
}
I also read some earlier articles about using string attributes on enum fields, but these strings can not pop up for external use.
Any helps? Thanks in advance.

I think its cause an error because a white space.
Try this
public enum City
{
LosAngeles,
SantaFrancisco,
Houston,
NewYork
}
Here is a sample of how to use enum.

Related

How to store a (partial or full) physical address in Swift

How can I store a persons mailing address? Say two different users entered the information differently, so if one user were to say 123 Main Street, City, State-ABV, and another just entered City, State ABV.
I was thinking keep it simple and just do it as a String like this
func getAddy(houseNumber: Int, nameOfStreet streetName: String, nameOfCity cityNme: String, nameOfState stateAbrv: String) -> String {
return "\(houseNumber) \(streetName) \(cityNme) \(stateAbrv)"
}
But I run into two problems. First the user might only enter partial data, and 2nd. Those street strings don't mean anything. It could say San Francisco or cheese. How can I give that meaning?
Is there an Address type?
You can use CNPostalAddress from the Contacts framework. It's a standalone class that doesn't actually require access to a user's contacts.

Store quotes in parse

So I am really new to parse and I have no idea how to store a famous quote and it's own author, so then I can use that information in my iOS app made with swift.
I have imported all the frameworks in order to make parse work but I don't know to to store that quotes with the authors and then retrieve the information to display the quote in a label and the author in another label. Please don't be rude, I don't get who to make this work.
So if you want to save a text and retrieve to Parse
let's say you want to save some text into a class called Data
Save
var data = "Swift is nice"
var object = PFObject(className:"Data")
object["message"] = data
object.saveInBackground()
So I use the saveInBackground method just for simplicity however if you should other saveInBackground method where you could check if there is no error while you are saving into Parse.
Retrieve
#IBOutlet weak var textlabel:UILabel!
var query = PFQuery(className:"Data")
query.getFirstObjectInBackgroundWithBlock({ (objects:PFObject?, error:NSError?) -> Void in
if error == nil {
let retrieveData = objects?.objectForKey("message") as! String
//so lets say you had a UILAbel
self.textlabel.text = retrieveData
}
})
I used the getFirstObjectInBackgroundWithBlock method because I assume that I have at least one object save in Parse. So if you are retrieve a lot of data you could findObjects method .
Hope that helps :)
To answer your comment on Lamars's fine answer:
Create a class ("Add class") "Quotes" in Parse, if you haven't already. Create a column in that class named "Quote", set it's type to String. Click "Add Row" and you will get a new row in your table. Double Click it's field and you can write your quote there.
This is me editing the usernameField in my Parse Class:
You could have another column named "Author" of type String, and just do the same thing, but if your app gets more advanced and you would like to display all the quotes from a specific author, you should add another class, named "Author". Add a column named "Name", double click and submit your name.
In your "Quotes" class, add a column named "Author", type Pointer, and make it point to your Author Class. Then copy the correct objectId from Pointer (let's sat Steve Jobs has objectId "12345678") and paste it to the "Author" column in Quotes. Now, if there's another quote by Steve Jobs, you can re-use that objectId, not having to store the name "Steve Jobs" more than once.
I understand you're new to Parse.com and maybe databases as well, but this way of creating relations is very good knowledge, if you want to design stuff in the future.
Parse has a great documentation, in Obj-C and Swift, check it out:
https://www.parse.com/docs/ios/guide

Facebook name ordering and displaying correctly based on country

I looking at splitting the name supplied by the Facebook API across two lines and I want this to display correctly depending of the country of origin of the person. So the western standard of
Given Name
Family Name
Where applicable, and
Family Name
Given Name
in countries where the names should be reversed
Facebook supply a number of name fields
name - The person's full name
name_format - The person's name formatted to correctly handle Chinese, Japanese, Korean ordering.
first_name - The person's first name
last_name - The person's last name.
I assume name is always [Given Name] [Family Name] (may also include middle name?)
name_format sounds like it'll be the name in the correct display order
I'm not sure if first_name and last_name is the indicator of display order, or is first_name = [given name] and last_name = [family name] as would be assumed in the US?
The real question is how can I split the Facebook display name into given name and family name and then ensure I'm displaying them in the correct order.
Just tried getting name_format back on a user with Chinese/Korean ordering (used typical English name for ease of reading):
Using https://developers.facebook.com/tools/explorer get a token (clicking Get Token button) and requesting the following fields:
me?fields=first_name, last_name, name, name_format
Returns
"first_name" = "John"
"last_name" = "Smith"
"name" = "Smith John"
"name_format" = "{first} {last}"
In this case you'd expect it to return "{last} {first}"
so looks like name_format is completely useless. I've tested it on two users, one with western name order and one like the above, both returned the same name_format value.
After some more research, it turns out the name_format does not return what the API documentation says, which is:
The person's name formatted to correctly handle Chinese, Japanese,
Korean ordering.
As detailed in the API, but something more akin to what the name would suggest, which is the formatting for the name. In my instance, the return from the API call is as follows.
"name": "Will Calderwood",
"name_format": "{first} {last}"
I think it's safe to assume that for a Korean locale it would be
"name": "Calderwood Will",
"name_format": "{last} {first}"
So the name_format can be used to break up the name and display it in the correct order.
The field first_name is the given name, the last_name is what you call "family name". To me it's not really clear where your problem is here to be honest.

Google Places API autocomplete specific city

I have some questions about google places api for android.
This is the request that is being called:
https://maps.googleapis.com/maps/api/place/autocomplete/json?sensor=false&key=API_KEY&components=country:hr&language=hr&input=lad
The issue is that I want only addresses within specific city. Is that possible?
Here is the quote from
Google Places API autocomplete
that suggests that it should work.
Blockquote the (regions) type collection instructs the Place service to return any result matching the following types:
locality
sublocality
postal_code
country
administrative_area1
administrative_area2
Blockquote the (cities) type collection instructs the Place service to return results that match either locality or administrative_area3.
So I would like to specify citry or a postal code in order to filter only addreses from that city.
--EDIT--
This approach doesn't work either.
maps.googleapis.com/maps/api/place/autocomplete/json?sensor=false&key=API_KEY&types=geocode&location=45.811093,15.974121&radius=12000&components=country:hr&language=hr&input=lad
Solution
I've added CIty name in input string
city_name+street like Zagreb+fal in order to get all the streets from Zagreb with fal* in their name.
It seems to be working oke.

Parsing an Address with T-SQL

I am trying to figure out how to parse an address using T-SQL and I suck at T-SQL. My challenge is this,
I have a table called Locations defined as follows:
- City [varchar(100)]
- State [char(2)]
- PostalCode [char(5)]
My UI has a text box in which a user can enter an address in. This address could be in the form of essentially anything (yuck, I know). Unfortunately, I cannot change this UI either. Anyways, the value of the text box is passed into the stored procedure that is responsible for parsing the address. I need to take what the person enters and get the PostalCode from the Locations table associated with their input. For the life of me, I cannot figure out how to do this. There are so many cases. For instance, the user could enter one of the following:
Chicago, IL
Chicago, IL 60601
Chicago, IL, 60601
Chicago, IL 60601 USA
Chicago, IL, 60601 USA
Chicago IL 60601 USA
New York NY 10001 USA
New York, NY 10001, USA
You get the idea. There are a lot of cases. I can't find any parsers online either. I must not be looking correctly. Can someone please point me to a parser online or explain how to do this? I'm willing to pay for a solution to this problem, but I can't find anything, I'm shocked.
Perhaps a CLR function might be a better choice than tsql. Check out http://msdn.microsoft.com/en-us/magazine/cc163473.aspx for an example of using regular expressions to parse some pretty complex string inputs into table value results. Now you get to be as creative as you please with your regex matching but the following regex should get you started:
(.*?)([A-Z]{2}),? (\d+)( USA)?$
If you're reluctant to use CLR functions, perhaps you have regex functionality in the calling system, like ASP.Net or PHP.