Questions tagged [associated-object]

60 questions
2
votes
1 answer

Rails creating duplicate record

I am trying to learn using rails. I was following http://guides.rubyonrails.org/getting_started.html I added the associated model. but when I create the new event..it also duplicates it. class EventsController < ApplicationController def create …
2
votes
1 answer

Rails 4: Correct way to create objects from other model from the controller

Using strong_params from Rails 4, what is the preferred best way to do this? I used the below solution but are uncertain if this is the best way to do it. ( it works though ) Example: game_controller.rb ( shortcut version!) # inside game controller…
Rubytastic
  • 15,001
  • 18
  • 87
  • 175
1
vote
1 answer

Objective-C NSString memory leak with objc_setAssociatedObject

I found a memory leak for NSString with objc_setAssociatedObject Test Code: int i = 0; while (YES) { @autoreleasepool { NSString *string = [[NSString alloc] initWithFormat:@"%d", i]; // Comment this line. Then the memory leak is…
Yanni
  • 580
  • 2
  • 6
  • 21
1
vote
1 answer

Can I add associated object to Swift Struct?

I would like to add an additional property to the Swift String. I used this approach few times on objects, but it seems that it does not work on struct. Although, I don't get any error... This is what I tried: var str = "Hello,…
Dave
  • 1,081
  • 6
  • 10
1
vote
1 answer

Accessing extra data in a sqlalchemy associated object

The User object can be involved with a Project in many different ways, specified by Job association table. In my template file, I'm trying to loop through all of the projects in current_user.projects and with each one, specify what the Job was for…
1
vote
0 answers

Explanation for unique association key in a stored property in Swift

I am referring to a question about emulating stored properties in Swift, and the answer from jou: How to have stored properties in Swift, the same way I had on Objective-C? Currently I am using that answer to add custom properties to…
Tom Major
  • 283
  • 1
  • 12
1
vote
2 answers

Access Objective-C Category's Property (Associated Reference) in Swift 3's Value Type

In my Objective-C class's .h file, I have created a Category for NSIndexPath like this: @interface NSIndexPath (YVTableView) @property (nonatomic, assign) NSInteger subRow; @end and in that class's .m file, I have implemented that like: static…
1
vote
2 answers

How to use selector (SEL) with objc_setAssociatedObject?

Can I use somehow parameter of type SEL with objc_setAssociatedObject without converting it to NSString type? Currently I'm using this code: objc_setAssociatedObject(thirdPartyObject, &kSelectorKey, NSStringFromSelector(selector),…
Krypt
  • 434
  • 4
  • 12
1
vote
1 answer

User Defined Runtime Attributes and Associated Objects

I'm currently trying to use User Defined Runtime Attributes in Xcode 6 with the following algorithm: Add custom properties to UIView class using Associated Objects #define ASSOCIATED_OBJECT_GETTER_AND_SETTER(propertyType, propertyName,…
Alexander
  • 959
  • 5
  • 11
  • 29
1
vote
2 answers

objc_getAssociatedObject returns the wrong value

Below is the code to associate an extra value with a button - (int)uniqueId { return (int)objc_getAssociatedObject(self, uniqueIdStringKeyConstant); } - (void)setUniqueId:(int)uniqueId { objc_setAssociatedObject(self,…
Tapas Pal
  • 7,073
  • 8
  • 39
  • 86
1
vote
1 answer

Using arrays in typoscript

I'm quite new to typoscript and I want to use an array to associate a subject to an email adress like this email_mapper { general = info@somewhere.com specific = me@somewhere.com } to_mail = email_mapper[GP:formhandler|subject] how can I do…
1
vote
1 answer

object c runtime associate object

associate object tutorial "The tutorial link gave me a clear concept of object-c runtime associate object" After reading the example code below, I have a small question. - (void)setAssociatedObject:(id)object { …
1
vote
1 answer

setter and getter as objc_setAssociatedObjec

I do not understand what mean this style and are there any benefits for standard setter/getter? - (UIViewController*)myVC { return objc_getAssociatedObject(self, kMJPopupViewController); } - (void)setMyVC:(UIViewController *) myVC…
user3358463
  • 125
  • 15
1
vote
1 answer

RoR: Find all associated objects of an array of objects

Working in rails, I am working to output a list of a User's classes for the Fall 2012 quarter. I have 3 models of importance here: User, Quarters, and Courses. Based on the other work I've done, I'm pretty certain my model associations are spot…
mattwd7
  • 57
  • 1
  • 8
0
votes
0 answers

Different associated object key in static framework when accessing outside

I wrote codes like below. this code is in static framework. private struct AssociatedKeys { static var someKey = "someKey" } extension SomeClass { public var someProperty: String? { get { return objc_getAssociatedObject(self,…
presto
  • 1