I want to reproduce declarative programming like in WPF on IOS(objective-c).
In WPF I could use a control like so:
<MediaElement Name="myVideo" Source="C:\WINDOWS\system32\oobe\images\ intro.wmv" Width="450" Height="400" >
The exact code would be:
MediaElement me = new MediaElement();
me.Id = "myVideo";
me.Height=450;
...
Can this be accomplished in a similar manner on objective-C(IOS 7)? Please give examples or hints on ways to implement this.
Is there any library that implements Composite pattern that I can use in IOS7?
Edit: This is a real question, and I want to implement this on a real project, if it can be done.
Edit 2: I want to transform a NSString to a xib file and display it as a control in a View?
*Edit 3:
I have a response from server in JSON
format like this :
{
"alignment" : "center",
"text" : "Just a text",
"type" : "label",
"textColor" : "black",
"width" : "300",
"height" : "44",
"backgroundColor" : "white",
"fontName" : "Helvetica",
"fontSize" : "15",
"x" : "75",
"y" : "200"
}
inside the implementation file to be interpreted as :
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(75, 200, 300, 44)];
label.backgroundColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:@"Helvetica" size:15];
label.text = @"Just a text";
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blackColor];
[self.view addSubview:label];
According to the title of your question it seems you are looking for a way to "take a string and make an object out of it".
It is kind of possible. I guess you already know how to parse the string.
You can always create object if you have the name of the class.
Key would be the name of the property being set.
And if the class is KVC compliant you can set its properties as if you were setting dicionary entries.
where @"John Doe" and @"name" would be part of original string - extracted by parsing.
Added for Q Edit2:
If you are thinking of making your own run-time xib files that could be created anytime and used as proper xib files then you are out of luck. xib files that "come with the app in application bundle" are compiled (ibtool).
What you could do is create your own "object factory" that takes and parses a text file and uses it as a blueprint for creating the object(s) runtime. If the result is supposed to be some kind of a
UIView
you might even use XML or JSON format to define the inter-view relations.Note that you couldn't use classes that were left-out during linking process. So you would have to make in-code dummy instances of all the classes you intend to be able to create with this "object factory".
EDIT: but this also sounds like your app could be rejected because your app would be able to "download new code" in a way.
From App Store Review Guidelines: