iOS – Map a root JSON array with ObjectMapper in swift

I finally solve my problem : The mapping method in the controller should be let json : AnyObject! = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &error) if (error != nil) { return completionHandler(nil, error) } else { var customer = Mapper<Customer>().mapArray(json)! //Swift 2 var customer = Mapper<Customer>().mapArray(JSONArray: json)! //Swift 3 } If it can help someone.

Testing if NSMutableArray contains a string object

What you’re doing should work fine. For example NSArray *a = [NSArray arrayWithObjects:@”Foo”, @”Bar”, @”Baz”, nil]; NSLog(@”At index %i”, [a indexOfObject:@”Bar”]); Correctly logs “At index 1” for me. Two possible foibles: indexOfObject sends isEqual messages to do the comparison – you’ve not replaced this method in a category? Make sure you’re testing against NSNotFound for … Read more

NSArray @property backed by a NSMutableArray

I would declare a readonly NSArray in your header and override the getter for that array to return a copy of a private NSMutableArray declared in your implementation. Consider the following. Foo.h @interface Foo @property (nonatomic, retain, readonly) NSArray *array; @end Foo.m @interface Foo () @property (nonatomic, retain) NSMutableArray *mutableArray @end #pragma mark – @implementation … Read more

NSArray adding elements

If you create an NSArray you won’t be able to add elements to it, since it’s immutable. You should try using NSMutableArray instead. Also, you inverted the order of alloc and init. alloc creates an instance and init initializes it. The code would look something like this (assuming getData is a global function): NSMutableArray *stringArray … Read more

How do copy and mutableCopy apply to NSArray and NSMutableArray?

copy and mutableCopy are defined in different protocols (NSCopying and NSMutableCopying, respectively), and NSArray conforms to both. mutableCopy is defined for NSArray (not just NSMutableArray) and allows you to make a mutable copy of an originally immutable array: // create an immutable array NSArray *arr = [NSArray arrayWithObjects: @”one”, @”two”, @”three”, nil ]; // create … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)