Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-05-2010, 12:03 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 10
slaterjohn is on a distinguished road
Default Functions In External File

In an app im developing i intend to have a very large function that will build a series of arrays. Because of its size i want to be able to store this function in an external file.

Similar to PHP's include file where you can "include" a file at a specific point in an application and the code would be executed as if it was local to the main file.

I noticed there is a #include available but i'm not sure it does what i expect.

I may be looking to do something impossible here or overlooking something very obvious so any help would be much appreciated.

Regards, John
slaterjohn is offline   Reply With Quote
Old 12-05-2010, 12:14 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Frankfurt
Posts: 9
shadowJohnny is on a distinguished road
Default

Hi!

What I do to solve this problem:
1. Create a new file with a class (.h and .m).
2. Create a method within this class that has the + modifier:
Code:
+(void)doSomething
3. Call the function by this:
Code:
[ClassName doSomething];
Maybe this helps.
shadowJohnny is offline   Reply With Quote
Old 12-05-2010, 12:23 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 10
slaterjohn is on a distinguished road
Default

It does thanks. But how would i go ahead and pull values from that array afterwards. I get errors saying they are not defined etc.
slaterjohn is offline   Reply With Quote
Old 12-05-2010, 12:32 PM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Frankfurt
Posts: 9
shadowJohnny is on a distinguished road
Default

I think the only way to do that is parameters and return values:
Code:
+(NSArray *)doSomething:(NSArray *)input
I don't know if there is a way to simulate the real PHP include function, but I doubt it.
shadowJohnny is offline   Reply With Quote
Old 12-05-2010, 12:42 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by slaterjohn View Post
In an app im developing i intend to have a very large function that will build a series of arrays. Because of its size i want to be able to store this function in an external file.

Similar to PHP's include file where you can "include" a file at a specific point in an application and the code would be executed as if it was local to the main file.

I noticed there is a #include available but i'm not sure it does what i expect.

I may be looking to do something impossible here or overlooking something very obvious so any help would be much appreciated.

Regards, John

Are you trying to include multiple source files at compile-time, or are you trying to invoke a compiled code library at run-time? Those are two very different things.

In C, you can use #include or #import to include one source file in another. #import is better, because it is smart about not including the same file more than once.

#import/#include has exactly the same effect as if you copied the entire contents of the included file and pasted in at the location of the #include statement.

Normally you use #import to include the header (.h) files of your project, but you can also #include the body of a method if you want to.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 12-05-2010, 12:55 PM   #6 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 10
slaterjohn is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Are you trying to include multiple source files at compile-time, or are you trying to invoke a compiled code library at run-time? Those are two very different things.

In C, you can use #include or #import to include one source file in another. #import is better, because it is smart about not including the same file more than once.

#import/#include has exactly the same effect as if you copied the entire contents of the included file and pasted in at the location of the #include statement.

Normally you use #import to include the header (.h) files of your project, but you can also #include the body of a method if you want to.

Basically what i want is to just include either the insides of a function or the function where i put #import. I have tried to #import a .m file with either a method or the contents of a method but i just get hundreds of errors.

My best guess is im doing something very noobish.
slaterjohn is offline   Reply With Quote
Old 12-05-2010, 01:04 PM   #7 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 10
slaterjohn is on a distinguished road
Default

I actually think the .m file was the issue. I changed it to a plain text document and it seems to work a treat.

Big thanks to both of you lovely lovely people.
slaterjohn is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 386
6 members and 380 guests
chemistry, daudrizek, HemiMG, jeroenkeij, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:54 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0