1

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];
Dani Pralea
  • 4,545
  • 2
  • 31
  • 49
radu florescu
  • 4,315
  • 10
  • 60
  • 92
  • Check the updates please. I already read documentation above and it did not help. – radu florescu Jan 08 '14 at 11:55
  • I want to use declarative programming to generate my UI in a dynamic way http://msdn.microsoft.com/en-us/library/vstudio/hh297100(v=vs.100).aspx – radu florescu Jan 08 '14 at 13:30
  • If you can give me proof of that with links to back you up, would be very nice. Thank you. – radu florescu Jan 08 '14 at 13:49
  • 3
    according to edit 3 you want to change only the appearance of an app. this might be useful: [WWDC2010 Session 117: "Building a Server-driven User Experience"](https://deimos.apple.com/WebObjects/Core.woa/BrowsePrivately/adc.apple.com.4092349126.04109539109.4144345611?i=1991648002) – vikingosegundo Jan 08 '14 at 14:26

1 Answers1

2

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.

id newObject =  [[NSClassFromString(@"classname") alloc] init];

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.

[newObject setValue:@"John Doe" forKey:@"name"];

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:

2.7 Apps that download code in any way or form will be rejected

Rok Jarc
  • 18,765
  • 9
  • 69
  • 124
  • does it say it HIG that "downloading" new code is prohitbited ? – Dani Pralea Jan 08 '14 at 14:05
  • Not in HIG but in App Store Review Guidelines. I am not saying that your app will get rejected but this kind of funcionality kind of violates this rule. – Rok Jarc Jan 08 '14 at 14:11
  • that's not downloading of code, just update of UI elements, worst case scenario adding some. – Dani Pralea Jan 09 '14 at 07:02
  • That is actually open for interpretation. If this is used to customize appearance only, then yes - it could be considered as downloading content. – Rok Jarc Jan 09 '14 at 09:31