Is it possible to add UIGestureRecognizer for single word in UILabel? - ios6

Is it possible to add UIGestureRecognizer for single word in UILabel?

Add UIGestureRecognizer for single word in UILabel by using TTTAttributedLabel.
https://github.com/mattt/TTTAttributedLabel

Related

Error when trying to set array in userdefaults: Thread 1: "Attempt to insert non-property list object

I have solved the issue now, thanks for your help. I shouldn't have tried to save arrays with UITextViews, but I should have saved their text as strings instead. Here was the original question:
I have tried a lot, and googled a lot, but I can't solve this problem on my own. Whenever I try to save an array in userdefaults, it just is not working. I get the following error:
Thread 1: "Attempt to insert non-property list object (\n "<UITextView: 0x14001f800; frame = (0 0; 355 180); text = 'D'; clipsToBounds = YES; gestureRecognizers = <NSArray: 0x600003f01d10>; layer = <CALayer: 0x6000031c83e0>; contentOffset: {0, 0}; contentSize: {355, 30}; adjustedContentInset: {0, 0, 0, 0}>"\n) for key content"
I don't know what a non-property list object is. And I do not know how to solve the problem. Below is the lines of code that do not work.
var contentList: [Any] = []
let cl = defaults.array(forKey: "content")!
if cl.count != 0{
contentList += cl
}
contentList.append(label)
defaults.setValue(contentList, forKey: "content")
If I take out the last line of code by turning it into a comment everything runs just fine. How should I replace that line of code? I essentially want to save an array of UITextViews and make it larger every time I call a fucntion (this code is part of a larger function). The reason why I have created another two lists (cl and contentList) is that it helps me with a problem down the line. What I cannot understand however, is why the last line of code doesn't work. If anyone has any ideas, please help me, it would be much appreciated.
Use only String as stated in comments :
var contentList: [String] = []
let cl = defaults.array(forKey: "content")!
if cl.count != 0{
contentList += cl
}
If lbText = label.text {
contentList.append(lbText)
defaults.setValue(contentList, forKey: "content")
}
You can only store a very limited list of data types into UserDefaults, commonly referred to as "property list objects" (Since property list (or plist) files will only store the same data types.
To quote the Xcode docs on UserDefaults, in the section titled "Storing Default Objects":
A default object must be a property list—that is, an instance of (or for collections, a combination of instances of) NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary [or Data, String, NSNumber, Date, Array, or Dictionary types in Swift.] If you want to store any other type of object, you should typically archive it to create an instance of Data.
(I added the equivalent Swift types to the above quote in square brackets, since it looks like Apple hasn't updated it for Swift.)
That's worded a little awkwardly. The idea is that you can only store data of the types listed. Because the Array and Dictionary types are "container" types, you can store any combination of arrays and dictionaries that contain combinations of any of the above types. For example, you can store an array that contains a dictionary, 3 dates, 2 floats, a Double, some Data, and 2 arrays, and those dictionaries and arrays can contain other dictionaries and/or arrays.)
It is almost always wrong to archive UIView objects like UITextViews. You should save the text properties of your text views instead.
If you want to manage a vertical stack of UITextView objects, I suggest adding a vertical stack view to your user interface, and then writing code that adds or removes UITextView subviews to your stack view. You should be able to find plenty of examples of adding and removing objects from stack views online. (It's really easy.)
If you want to manage a scrolling list of feeds of arbitrary length, you might want to use a table view or collection view instead. Those require that you set up a data model and implement a "data source". That takes a little practice to get right, but is very powerful.

Swift: How do you use a variable in an array?

I am using a pod called iOSDropDown to display a dropdown selection menu for a textfield. I am getting a list of data from php to populate that selection menu that Im storing in a variable.
The PHP data passed stored in a swift variable looks like this when printed -> "option01","option02","option03"... and so on. This is dynamic data that will change that is why I am retrieving from PHP/MYSQL Database instead of just manually typing in the options in the Swift array.
Below is my code. What I am trying to do is use the "dropdownData" variable that holds the options for the array. Each option should be in its own row and separately selectable. What I am getting is one option, one string of coding with all my options as shown in the picture below.How would I use the dropdownData variable to display options instead of one string, one option?
dropdownData = "option01","option02","option03"... etc. ALL OPTIONS STORED IN THIS ONE ARRAY
let dropdownData : String = (dumpsArray[indexPath.row] as AnyObject).value(forKey: "dropdownData") as! String
.
cell.nameField.optionArray = [dropdownData]
Image
In the image above there should be no comma after styrofoam cooler... the next product should be the next option displaying under the styrofoam cooler and separately selectable.
Seems like dumpsArray[indexPath.row] as AnyObject).value(forKey: "dropdownData") returns a String where names are comma separated,
so
if let nameString = dumpsArray[indexPath.row] as AnyObject).value(forKey: "dropdownData") as? String {
let namesArray = nameString.components(separatedBy: ",")
cell.nameField.optionArray = namesArray
}
That should do

How to add space in WordPress post content without adding a new line

I have a google sheets document with content that goes into a WordPress post. I am trying to add non-breaking space inside the formulas. The problem is that when I add the non-breaking space I need to create it on a new line. Example:
This is random text which I need to break (Doesn't work)
This works
This is random text which I need to break
If I break the text with the above and below text, the google sheets formula wraps the entire text inside double quotation marks, something I want to avoid. Also, adding this between text doesn't create space where the entity has been added.
In short, what I am looking for is a way to create non-breaking blank space between two sentences where appears. So that this random text here becomes this
So that this random
now breaks and leaves a blank space like so
My google sheets formula is something like this but you don't have to use it ="<h1>"&CONCATENATE(UPPER(A2 &" and " &C2)&" This is Random text")&"</h1><b>"&UPPER(A2 &" and " &C2)&"</b>"&A1&"Date: "&TEXT(BT2,"dddd, dd MMMM yyyy")&"<br>Examples at "&B2&" NOW <b>"&A2&"</b> vs <b>"&C2&"</b> for "&A1&" time period.
Link to google sheets document https://docs.google.com/spreadsheets/d/1qdyMPqbIg6tUOOPrHDoVqzHpQKQhLh4_BT8IhsjE2ig/edit?usp=sharing
Any ideas please?
try:
=REGEXREPLACE("<h1>"&UPPER(A2&" and "&C2)&" This is Random text"&
"</h1><b>"&UPPER(A2&" and "&C2)&"</b>"&A1&"Date: "&TEXT(BT2, "dddd, dd MMMM yyyy")&
"<br>Examples at "&B2&" NOW <b>"&A2&"</b> vs <b>"&C2&"</b> for "&A1&" time period.",
"( )", CHAR(10)&"$1")
to avoid wrapping the copied string into double quotes use:
={""; REGEXREPLACE("<h1>"&UPPER(A2&" and "&C2)&" This is Random text"&
"</h1><b>"&UPPER(A2&" and "&C2)&"</b>"&A1&"Date: "&TEXT(BT2, "dddd, dd MMMM yyyy")&
"<br>Examples at "&B2&" NOW <b>"&A2&"</b> vs <b>"&C2&"</b> for "&A1&" time period.",
"( )", CHAR(10)&"$1")}
one step further would be entering the cell before copying it...
select cell
press ENTER
press CTRL + A
press CTRL + C

Update UIlabel text with a String

I have a label in the prototype table view cell, and also a UITextviewfield, I want to update the text of the label by using UITextviewfield.
first I created a struct:
struct CellElements {
let title: UILabel
}
then an array:
var list = [CellElements] ()
then I use these codes to add the text inside the UITextfieldto the list array and later I will add them in the table view.
#IBOutlet weak var inputField: UITextField!
#IBAction func addName(_ sender: UIButton) {
list.append(inputField.text)
}
the problem is, swift doesn't let me to do that with this error
Cannot convert value of type 'String?' to expected argument type 'CellElements'
I will appreciate for your help in advance.
list is an array of CellElements. When you attempt to append to that array, you need to add a CellElements instance.
But your line:
list.append(inputField.text)
is attempting to append a String. Hence the error since String isn't CellElements.
What you want to do is to create an instance of CellElements from the text field and then append that instance.
list.append(CellElements(title: inputField.text!))
Note that you need a String and inputField.text is an optional String. This is a case where you can safely force-unwrap an optional. See the documentation for UITextField text for why this is safe.

AngularJS Get words with a prefix from text box

I am trying to get words with a certain prefix when a user types into a text box. For example, let's say I want all words in a text box that begins with "#". How would I go about getting these words?
One way to do it is to use the JavaScript split() method.
Let's say you get the value of a user input into one of your variables. You can use this method to get an array of String of the words that start with the prefix you chose.
var input = "#This is what the #user typed";
var splitArray = input.split("#");
// splitArray = ["This is what the", "user typed"]

Resources