Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Array1 : { A , B , C }
Array2 : { 1 , 2 , 3 }
I need to combine of this array list like:
Combine array :
{
A(1),
B(2),
C(3)
}
How can I implement this?
you can use NSDictionary
NSDictionary *dict = [NSDictionary dictionaryWithObjects:array1
forKeys:array2];
NSString *value = dict[#"1"]; //value = #"A";
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
I'm working on a search bar within my iOS App and have a SQLite offlite db with about 300k records in it. The text name is how I'd like the search to person. I have the following code working which just does a basic search on String.
func searchList(searchQuery: String, filter: SearchFilter, limit: Int = 20, page: Int = 0) -> outputItems {
guard let db = self.db else { return [] }
var outputTable = Table(OfflineDBSchema.DBTables.outputTable.rawValue)
if !searchQuery.isEmpty {
outputTable = outputTable.filter(OfflineoutputTableColumnExpressions.name.lowercaseString.like("%\(searchQuery.lowercased())%"))
}
I'm looking for a search basic algorithm that is a little bit "smarter" which is better at finding those keywords and returning a results back with most relevant terms at the top.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 months ago.
Improve this question
Hello I wrote this little piece of code, but I have the impression that it is not optimal, indeed as the field variable is in get only : I can not directly change it .... but I am junior : so I would be delighted if someone has a better idea :) thank you .
let keyword = ["potatoes","garlic"]
var field: String {
var element = ""
keyword.forEach {
element += "&field=" + $0
}
return element
}
a shorter code coming from professionalswift developper :)
this would be better
let keyword = ["potatoes","garlic"]
var field: String {
return keyword.map { "&field=\($0)"}.joined()
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I use below line of code to allocate an Object(Suppose my Object name is Car) dynamically.
[self initliazieObject:[Car class]]
- (id)initliazieObject:(Class)model{
id record = [[model alloc] init];
return record;
}
How I can do this in swift 3.
Exactly as in Objective-C. Try this in a playground:
class Car : NSObject {}
func factory(type:NSObject.Type) -> NSObject {
return type.init()
}
let c = factory(type:Car.self)
print(type(of:c)) // Car
(We can get fancy and do clever things with generics or Self to specify the type of the returned object more precisely, but my goal in this code is simply to do things the dumb way, just like Objective-C.)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string *strSearchNumber = #"9970405060" and want to check whether it is present in string *strPhoneMobile = #"+91997040560"
How can I check if last 6 or 8 characters of my string are present in some other string. Thanks in advance.
Simply use -[NSString hasSuffix:].
Use the NSString method hasSuffix:
NSString *strSearchNumber = #"9970405060";
NSString *strPhoneMobile = #"+91997040560";
if ([strPhoneMobile hasSuffix: strSearchNumber]) {
// do something
}
How do I check if a string contains another string in Objective-C?
Better then just checking the end or front of the string. You should check if the string contains the other bit of string. The link above will give you the answer.
Underneath the short version of the answer.
NSString *string = #"hello bla bla";
if ([string rangeOfString:#"bla"].location == NSNotFound) {
NSLog(#"string does not contain bla");
} else {
NSLog(#"string contains bla!");
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I've got an NSMutableArray called Letters, and it contains instances of a UIImageView subclass. I am trying to loop through them and assign them new values
for (int i=0 ;i<26;i++)
{
[letters objectAtIndex:i] = [[typeLetters alloc]initWithManager:self atX:startX andY:startY withSideLenght:48 andName:[letterNames objectAtIndex:i] andPng:[letterNames objectAtIndex:i]];
}
This doesn't work though. Xcode says "Cannot assign to expression", but when I try to assign new values to each array item individually, outside of the array, it works. Do you know why this would be?
EDIT: Nevermind. I'm sorry. I should have looked into arrays a bit more.
The method you're looking for is.-
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;
for (int i=0 ;i<26;i+=1) {
[letters replaceObjectAtIndex:i withObject:[[typeLetters alloc]initWithManager:self atX:startX andY:startY withSideLenght:48 andName:[letterNames objectAtIndex:i] andPng:[letterNames objectAtIndex:i]]];
}
array notation works: letters[i] = blah
But you should probably be using fast enumeration:
for(id letter in letters) {
letter = blah;
}
You need to use replaceObjectAtIndex:withObject:, but you should really use the new array syntax:
letters[i] = ...