Questions tagged [associated-object]

60 questions
0
votes
1 answer

Why weak property of associated object is not nilled out if I call its getter?

Though it's kind of stupid in 2020 that I'm still asking question about ObjC, please be patient and considerate... I'm reading the source code of BloksKit and ran into a weird situation. #import @interface…
刘maxwell
  • 187
  • 10
0
votes
1 answer

Understanding UnsafeRawPointer in objc_setAssociatedObject

I'd like to set n number of associated objects to an object in Swift My understanding is the usual pattern for the UnsafeRawPointer reference is like this... static var reference = "someRef" public func add(to myObject: AnyObject) { let adding…
Magoo
  • 2,552
  • 1
  • 23
  • 43
0
votes
1 answer

Associated objects and Swift arrays

I have an associated object on a view extension that contains an array (a mutable array in this case). var queue: NSMutableArray { get { if let queue = objc_getAssociatedObject(self, &Key.queue) as? NSMutableArray { return…
Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
0
votes
1 answer

How can you extract associated values from a specific instance of an enum's case?

Consider this enum... enum SelectionMode { case none (position:TextPosition) case normal (startPosition:TextPosition, endPosition:TextPosition) case lines (startLineIndex:Int, endLineIndex:Int) } If it's passed into a function,…
Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
0
votes
1 answer

How can I associate story_author name with request.user?

My first problem is once I save a story, the story.author will not associate with request.user. So it brings to another problem, I have to add story_author from user list, and then select an author for the story manually. Here is my damin looks…
0
votes
1 answer

AssociatedObject.Content throws exception after a certain scope

I am attaching a behaviour for some usercontrols and when I add UI elements (Please see the IsEnable() method) it works fine. After a certain point when a notification comes, I want to update the Texblock that was added as content to the user…
nikhil
  • 1,578
  • 3
  • 23
  • 52
0
votes
3 answers

How to fetch previous values of associated records?

When working with many-to-many relationships, I need to maintain a log file recording the changed values. Using the before_save and after_save callbacks works fine for the main (has_many) model itself but in the before_save callback the associated…
GTeley
  • 23
  • 9
0
votes
0 answers

Cannot retrieve associated object

I am setting my associated object in my cellForRowAt: method like this: objc_setAssociatedObject(cell.changeBtn, &self.appointmentHandle, appt, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) cell.changeBtn.addTarget(self, action:…
steventnorris
  • 5,656
  • 23
  • 93
  • 174
0
votes
1 answer

cant set stored property with associated object in extention

I have custom class, and I want to extend it and add stored property, one of solutions I found is to do it with Associated objects. My Code looks like that: import ObjectiveC var kSomeKey = "s" extension ProductCategory { var parent:…
Melany
  • 466
  • 7
  • 20
0
votes
2 answers

associate tabcontrol tab with string

I have an application that uses a TabControl to hold a RichTextBox. The user has the ability to open more tabs as they wish. I need a way to associate each tab with a string, so that I can store the filepaths for saving. To clarify, When opening a…
0
votes
0 answers

OData with associated objects but not inline

I am trying to understand OData... I know the $expand parameter and it is nearly what I need but: The returned, embedded data is highly redundant. This leads me to the question: How can I get the associated objects as references AND a separate list…
eventhorizon
  • 2,977
  • 8
  • 33
  • 57
0
votes
2 answers

How to use associated objects with enums?

I have a ViewController to which I added two new properties using associated objects: an enum and a string (string version is taken from here) Here is my example code: extension UIViewController { private struct AssociatedKeys { static…
Adrian
  • 19,440
  • 34
  • 112
  • 219
0
votes
2 answers

Getting id of associated child records in factory_boy

I have a function with a number of parameters, then a specialized instantiation of that function, with some settings for each of the function's parameters. So I have a structure like the following: class Function(models.Model): name =…
Chris
  • 5,664
  • 6
  • 44
  • 55
0
votes
2 answers

Objective-C runtime associate object with NSMutable dictionary

Reference from this post link I implemented a similar category using the same concept of using NSMutableDictionary to store the information I need. But there is one thing confuses me in the original post - (NSMutableDictionary…
user1316408
  • 37
  • 1
  • 2
  • 8
0
votes
1 answer

Create associated records in model after create

I have a model, MyModel, which should, after it is created, created associated records of type MyAssociation. I need to run code like the below after a create on the MyModel: myass = MyAssociation.new myass.mymodel_id = self.id myass.save What is…
steventnorris
  • 5,656
  • 23
  • 93
  • 174