Question: I have a query of this type:

```
    Select addMovies.MovieName, GivenBy.UserName, TimeOfReview, Review 
    FROM Users, Reviews, given, addMovies 
    WHERE Reviews.ReviewId = given.ReviewId AND GivenBy.UserName = addMovies.UserName
    ORDER BY TimeOfReview DESC

```

Where schemas of individual tables are of the form

```
   Users (UserName, Password, EmailId, Loc, Info)
   Reviews (ReviewId, ReviewRating, Review)
   Given (ReviewId, UserName)
   addMovies (MovieName, UserName)

```

I am trying to obtain reviews given by a particular user, but its giving me the errors:

**The multi-part identifier "GivenBy.UserName" could not be bound.**

**The multi-part identifier "GivenBy.UserName" could not be bound.**

Could anyone please let me know whats wrong, and what could I do to correct this?

Answer: 
From the reference documents on [Objective-C Runtime Reference](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/ObjCRuntimeRef/#//apple_ref/c/func/objc_setAssociatedObject):

> 
> You use the Objective-C runtime
>  function `objc_setAssociatedObject` to
>  make an association between one object
>  and another. The function takes four
>  parameters: the source object, a key,
>  the value, and an association policy
>  constant. The key is a void pointer.
> 
> 
> * The key for each association must be unique. A typical pattern is to
>  use a static variable.
> * The policy specifies whether the associated object is assigned,  
> 
>  retained, or copied, and whether the  
> 
>  association is be made atomically or  
> 
>  non-atomically. This pattern is  
> 
>  similar to that of the attributes of  
> 
>  a declared property (see “Property  
> 
>  Declaration Attributes”). You specify 
>  the policy for the relationship using 
>  a constant (see  
> 
>  objc\_AssociationPolicy and  
> 
>  Associative Object Behaviors).
> 
> 
> 

Establishing an association between an array and a string

```
static char overviewKey;

NSArray *array =

    [[NSArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];

// For the purposes of illustration, use initWithFormat: to ensure

// the string can be deallocated

NSString *overview =

    [[NSString alloc] initWithFormat:@"%@", @"First three numbers"];

objc_setAssociatedObject (

    array,

    &overviewKey,

    overview,

    OBJC_ASSOCIATION_RETAIN

);

[overview release];

// (1) overview valid

[array release];

// (2) overview invalid

```

> 
> At point 1, the string overview is
>  still valid because the
>  OBJC\_ASSOCIATION\_RETAIN policy
>  specifies that the array retains the
>  associated object. When the array is
>  deallocated, however (at point 2),
>  overview is released and so in this
>  case also deallocated. If you try to,
>  for example, log the value of
>  overview, you generate a runtime
>  exception.
> 
> 
>
To answer your revised question:

> 
> What is the point in associating the device with the view controller if it's already an instance variable?
> 
> 
> 

There are several reasons why you might want to do this. 

* the Device class doesn't have a controller instance variable, or property and you can't change it or subclass it e.g. you don't have the source code.
* you want two controllers associated with the device object and you can't change the device class or subclass it.

Personally, I think it is very rare to need to use low level Objective-C runtime functions. This looks like a code smell to me.