Welcome, Guest
Username Password: Remember me

Specify placeholders in class definition
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Specify placeholders in class definition

Specify placeholders in class definition 1 year, 4 months ago #1

Hi!

I was wondering if there was a quick way to specify the placeholders of fields at the class definition? I'd like something similar to this:

SCClassDefinition *sampleClassDef =
[SCClassDefinition definitionWithEntityName:@"Sample"
withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"propA", @"propB", nil],
withPlaceHolders: [NSArray arrayWithObjects:@"placeholder for propA", @"placeholder for propB", nil]];


Thanks!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 149
  • Karma: 8

Re: Specify placeholders in class definition 1 year, 4 months ago #2

Hey Harold,

You just need to set the property definition's attributes to an SCTextFieldAttributes instance:

 
...
SCPropertyDefinition *propADef = [sampleClassDef propertyDefinitionWithName:@"propA"];
propADef.attributes = [SCTextFieldAttributes attributesWithPlaceholder:@"placeholder for propA"];
...
 


Hope this helps.

Have a happy new year
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Specify placeholders in class definition 1 year, 4 months ago #3

Hi again!

Thanks for the tip but i wanted something generic that could be set at classdefinition. Like the code i mentionned (see below...the withPlaceHolders part). A way to pass an array of placeholders rather then defining them in each property definituions.


 
SCClassDefinition *sampleClassDef =
[SCClassDefinition definitionWithEntityName:@"Sample"
withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"propA", @"propB", nil],
withPlaceHolders: [NSArray arrayWithObjects:@"placeholder for propA", @"placeholder for propB", nil]];
 


Cheers!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 149
  • Karma: 8

Re: Specify placeholders in class definition 1 year, 4 months ago #4

Hi again Harold,

The code sample I mentioned above is used at class definition time. Is there is something I am missing here? Here is how the full code segment should look like:

 
...
SCClassDefinition *sampleClassDef = [SCClassDefinition definitionWithEntityName:@"Sample"
withManagedObjectContext:managedObjectContext
withPropertyNames:[NSArray arrayWithObjects:@"propA", @"propB", nil]];
SCPropertyDefinition *propADef = [sampleClassDef propertyDefinitionWithName:@"propA"];
propADef.attributes = [SCTextFieldAttributes attributesWithPlaceholder:@"placeholder for propA"];
SCPropertyDefinition *propBDef = [sampleClassDef propertyDefinitionWithName:@"propB"];
propBDef.attributes = [SCTextFieldAttributes attributesWithPlaceholder:@"placeholder for propB"];
...
 


The problem with creating an additional SCClassDefinition initializer with the "withPlaceHolders" parameter (as you suggested) is an architectural one: not all class properties are necessarily of type text field. This is why we designed each property type with its own unique attributes.

Having said that, if you wish, you can create a new SCClassDefinition category with the following method:

 
// Note: the following code assumes propertyNames.count equals placeholders.count
+ (id)definitionWithEntityName:(NSString *)entityName
withManagedObjectContext:(NSManagedObjectContext *)context
withPropertyNames:(NSArray *)propertyNames
withPlaceholders:(NSArray *)placeholders
{
SCClassDefinition *classDef = [[[[self class] alloc]
initWithEntityName:entityName
withManagedObjectContext:context
withPropertyNames:propertyNames] autorelease];
 
for(int i=0; i<classDef.propertyDefinitionCount; i++)
{
SCPropertyDefinition *propertyDef = [classDef propertyDefinitionAtIndex:i];
if(propertyDef.type == SCPropertyTypeTextField)
{
propertyDef.attributes = [SCTextFieldAttributes attributesWithPlaceholder:[placeholders objectAtIndex:i]];
}
}
 
return classDef;
}
 
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Specify placeholders in class definition 1 year, 4 months ago #5

Thanks for the tip!

Regards!
  • codebonbon
  • OFFLINE
  • Expert Boarder
  • Posts: 149
  • Karma: 8
  • Page:
  • 1
Time to create page: 1.01 seconds