Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
double sulk
Jul 2, 2010

Ok, I feel like an idiot because I've spent hours trying to figure this out and literally cannot find any good resources on classes using protocols and physically implementing them. Apple tells you how to make a protocol, but as far as I can read, it does nothing as far as physically implementing its properties into objects that display on the screen.

I want to make a very basic web browser. I have the framework set up with forward/back/reload/go buttons, but for the life of me cannot figure out how to make a UITextField address bar display the keyboard as a UIKeyboardTypeURL. I figured I would implement an AddressBar class which inherits from UITextField, and conforms to UITextInputTraits, but from there I don't know how to implement those specific properties I want, and so I get a 'default' keyboard when the application runs. As far as I've understood, I still have to declare AddressBar like a normal IBOutlet. I feel like once I understand the protocol stuff and how to implement them, things will be so much easier.

Here is code I used; no matter how laughably bad it is, tell me where I type in what's likely a couple lines to make the keyboard show. I'm sure I probably hosed up somewhere in the properties. Pardon the lack of my own comments because I have like 30-40 lines of my own code at most and it didn't seem necessary. The AppDelegate .h/.m aren't modified since I didn't see a need to do so just yet. I'm trying really hard and I know I should be able to do this stuff, and I have at least a semblance of *something* working, but there are a few key things I seem to not understand just yet. If you can just correct my code or do something with it regarding how to specifically achieve what I want to achieve in this given situation, it would probably help a lot. I'm also going to kill myself if there's a simpler solution than tying the address bar into a UITextField.

AddressBar.h:

code:
#import <Foundation/Foundation.h>

@interface AddressBar : UITextField <UITextInputTraits> {
    @private
    // I'm unsure if anything should go here
}

// Implementing the required properties listed for UITextInputTraits

@property(nonatomic) UITextAutocapitalizationType autocapitalizationType;
@property(nonatomic) UITextAutocorrectionType autocorrectionType;
@property(nonatomic) BOOL enablesReturnKeyAutomatically;
@property(nonatomic) UIKeyboardAppearance keyboardAppearance;
@property(nonatomic) UIKeyboardType keyboardType;
@property(nonatomic) UIReturnKeyType returnKeyType;
@property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry;
@property(nonatomic) UITextSpellCheckingType spellCheckingType;

@end
AddressBar.m:

code:
#import "AddressBar.h"

@implementation AddressBar

@synthesize autocapitalizationType, autocorrectionType,
            enablesReturnKeyAutomatically, keyboardAppearance,
            keyboardType, returnKeyType, secureTextEntry, spellCheckingType;
@end
SWViewController.h

code:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "AddressBar.h"

@interface SWViewController : UIViewController

@property (nonatomic, assign) IBOutlet UIWebView *webView;
@property (nonatomic, assign) IBOutlet AddressBar *address;
    
@property (nonatomic, assign) IBOutlet UIToolbar *topBar;
@property (nonatomic, assign) IBOutlet UIBarButtonItem *back;
@property (nonatomic, assign) IBOutlet UIBarButtonItem *forward;
@property (nonatomic, assign) IBOutlet UIBarButtonItem *go;
@property (nonatomic, assign) IBOutlet UIBarButtonItem *reload;
@property (nonatomic, assign) IBOutlet UIBarButtonItem *bookmarks;

-(IBAction)go:(id)sender;
-(IBAction)goBack:(id)sender;
-(IBAction)goForward:(id)sender;
-(IBAction)reload:(id)sender;
-(IBAction)loadBookmarks:(id)sender;
@end
SWViewController.m
code:
#import "SWViewController.h"

@implementation SWViewController

@synthesize webView, topBar, go, back, forward, reload, bookmarks;
@synthesize address;

#pragma mark - Navigation Buttons

-(IBAction)go:(id)sender
{
    NSURL *url = [NSURL URLWithString:address.text];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
    [webView loadRequest:request];
}

-(IBAction)goBack:(id)sender
{
    if([webView canGoBack])
    {
        [webView goBack];
        if ([webView isLoading] == true) 
        {
            [address setText:webView.request.URL.absoluteString];
        }
    }
}

-(IBAction)goForward:(id)sender
{
    if ([webView canGoForward])
    {
        [webView goForward];
        if ([webView isLoading] == true) 
        {
            [address setText:webView.request.URL.absoluteString];
        }
    }
}

-(IBAction)reload:(id)sender
{
    [webView reload];
}

-(IBAction)loadBookmarks:(id)sender
{
    // empty function I haven't set up
}

#pragma mark - Lifecycle updates

// this is a broken function, I want the address to update the text of the URL 
// based on the string and I couldn't figure out how to do this, either. this has 
// just been sitting here so it's probably got to do with protocols being wrong 
// (and I don't fully understand them yet, obviously), so ignore it, I guess

-(void)webViewDidFinishLoad:(UIWebView *)webViewer
{
    [address setText:webView.request.URL.absoluteString];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

    // Cut out all the start-up stuff here that is put in by default to save space,
    // didn't do anything with it

@end

Adbot
ADBOT LOVES YOU

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane
Don't subclass UITextField. Just use a UiTextField, and when initializing it, do:

myTextField.keyboardType = UIKeyboardTypeURL;

UITextField implements UITextInputTraits already. What's happening with your code is that it's keeping track of whatever traits you assign to it, but the superclass has no idea that they exist or what to do with them.

double sulk
Jul 2, 2010

PT6A posted:

Don't subclass UITextField. Just use a UiTextField, and when initializing it, do:

myTextField.keyboardType = UIKeyboardTypeURL;

UITextField implements UITextInputTraits already. What's happening with your code is that it's keeping track of whatever traits you assign to it, but the superclass has no idea that they exist or what to do with them.

Where am I explicitly doing this? Every impression I get is to use it in a viewDidLoad method or initWithCoder method, but StackOverflow has numerous Q&As that give different answers as to what to do. I'm using a Storyboard for the project (may as well get used to them), and maybe that's affecting it, but as far as I understand, I should just be able to do this within that method and it should work:

code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    address.keyboardType = UIKeyboardTypeURL;
}
Is this incorrect? If I can get a correct code sample to look at, it may make more sense.

Doc Block
Apr 15, 2003
Fun Shoe
Yes, that's all you have to do. Or you can set it in Interface Builder.

Also, think of a protocol as a contract between two objects/classes. When you declare that a class conforms to a protocol, you are just saying that the class implements the parts of the protocol that are marked @required in the protocol's header file, and may or may not implement any parts of the protocol marked as @optional.

That's it. You still have to go and implement those methods.

Doc Block fucked around with this message at 03:24 on Jan 10, 2012

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

Sulk posted:

Where am I explicitly doing this? Every impression I get is to use it in a viewDidLoad method or initWithCoder method, but StackOverflow has numerous Q&As that give different answers as to what to do. I'm using a Storyboard for the project (may as well get used to them), and maybe that's affecting it, but as far as I understand, I should just be able to do this within that method and it should work:

code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    address.keyboardType = UIKeyboardTypeURL;
}
Is this incorrect? If I can get a correct code sample to look at, it may make more sense.

Yeah, that should be working. You could try viewWillAppear too, but viewDidLoad should work. You can also select the type of keyboard you want for the text field in Interface Builder too.

dizzywhip
Dec 23, 2005

I'm having an annoying issue with getting text to center smoothly. I have some numbers that I'm trying to draw centered inside some circles, and depending on the size of the circle (which scales with the size of the view), the number will usually be off by a couple pixels horizontally, vertically or both. An example:





The number jitters around as the view is resized. I think the problem might be that the position of the text is getting rounded off to the nearest integer.

Does anyone know how to draw text at a sub-pixel position or have any other ideas on how to get the numbers to stay in place? I'm just using NSString's drawInRect:withAttributes: method with a center-aligned paragraph style and manually centering the rect's vertical position. Also this is on OS X, not iOS.

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane
Oh Jesus, I just got a call (at half past midnight in this timezone, to be clear) from a woman who could barely speak English and was having trouble installing an app or using her credit card or some combination of the above. Maybe putting my phone number on my website was not a great idea (either that or I should just ignore my business phone after a certain time...)

Has anyone else had a bizarre experience like that?

bumnuts
Dec 10, 2004
mmm...crunchy
Has the behavior of the keyboard changed in 5.0? One of my views is automatically getting its frame adjusted when the keyboard appears/disappears. Under 4.3 the frame doesn't get changed. I can't find anything in the documentation that mentions any change. Anyone come across this?

LP0 ON FIRE
Jan 25, 2006

beep boop
When I switch tabs in Xcode, sometimes it's scrolled to totally the wrong position. I have to go up to the method selection and select it. Does anyone know what's going on here? Am I doing something wrong, or is it just a bug?

wellwhoopdedooo
Nov 23, 2007

Pound Trooper!

PT6A posted:

Oh Jesus, I just got a call (at half past midnight in this timezone, to be clear) from a woman who could barely speak English and was having trouble installing an app or using her credit card or some combination of the above. Maybe putting my phone number on my website was not a great idea (either that or I should just ignore my business phone after a certain time...)

Has anyone else had a bizarre experience like that?

You published a support number on the internet. If I was that lady, I'd think it was bizarre that the helpdesk rep sounded like I just woke him up.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Gordon Cole posted:

I'm having an annoying issue with getting text to center smoothly. I have some numbers that I'm trying to draw centered inside some circles, and depending on the size of the circle (which scales with the size of the view), the number will usually be off by a couple pixels horizontally, vertically or both. An example:





The number jitters around as the view is resized. I think the problem might be that the position of the text is getting rounded off to the nearest integer.

Does anyone know how to draw text at a sub-pixel position or have any other ideas on how to get the numbers to stay in place? I'm just using NSString's drawInRect:withAttributes: method with a center-aligned paragraph style and manually centering the rect's vertical position. Also this is on OS X, not iOS.

Check out CGContextSetShouldSmoothFonts and CGContextSetShouldSubpixelPositionFonts. You can use [[NSGraphicsContext currentContext] graphicsPort] in your -drawRect: to get access to a CGContext.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

bumnuts posted:

Has the behavior of the keyboard changed in 5.0? One of my views is automatically getting its frame adjusted when the keyboard appears/disappears. Under 4.3 the frame doesn't get changed. I can't find anything in the documentation that mentions any change. Anyone come across this?

I haven't seen any changes like this. Is it a custom class of UIView that you're having problems with, or something in UIKit?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

LP0 ON FIRE posted:

When I switch tabs in Xcode, sometimes it's scrolled to totally the wrong position. I have to go up to the method selection and select it. Does anyone know what's going on here? Am I doing something wrong, or is it just a bug?

Pretty sure you're just getting the best that Xcode has to offer.

dizzywhip
Dec 23, 2005

pokeyman posted:

Check out CGContextSetShouldSmoothFonts and CGContextSetShouldSubpixelPositionFonts. You can use [[NSGraphicsContext currentContext] graphicsPort] in your -drawRect: to get access to a CGContext.

That sounds like exactly what I need! I'll check it out when I get home. Thanks!

Edit: No luck :( It seems to have no effect.

dizzywhip fucked around with this message at 05:38 on Jan 11, 2012

bumnuts
Dec 10, 2004
mmm...crunchy

pokeyman posted:

I haven't seen any changes like this. Is it a custom class of UIView that you're having problems with, or something in UIKit?

It's a subclass of UITableViewController, but I haven't overridden anything to do with the keyboard. It looks like the OS is automatically adjusting the contentInset.bottom to be the height of the keyboard. It's nice that it does this (and frankly should have done this all along) but it makes it hard to have the same code work across 4.x and 5.x.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

bumnuts posted:

It's a subclass of UITableViewController, but I haven't overridden anything to do with the keyboard. It looks like the OS is automatically adjusting the contentInset.bottom to be the height of the keyboard. It's nice that it does this (and frankly should have done this all along) but it makes it hard to have the same code work across 4.x and 5.x.

UITableViewController does try to get out of the way of the keyboard sometimes, but it's hardly new.

Text, Web, and Editing Programming Guide posted:

Note: As of iOS 3.0, the UITableViewController class automatically resizes and repositions its table view when there is in-line editing of text fields.

Are you calling up to super in your -loadView and -viewWillAppear: and so on?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Gordon Cole posted:

That sounds like exactly what I need! I'll check it out when I get home. Thanks!

Edit: No luck :( It seems to have no effect.

Is the background transparent? I think it needs to be at most semitransparent for subpixel rendering to happen.

dizzywhip
Dec 23, 2005

pokeyman posted:

Is the background transparent? I think it needs to be at most semitransparent for subpixel rendering to happen.

It's totally opaque. I don't know if it matters for this particular situation, but I should mention that I'm using a non-layer backed view. I know layer-backed views have weird issues with doing sub-pixel text rendering, but those shouldn't apply here.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Cocoa With Love had a post that might be helpful, it includes positioning a glyph:

http://cocoawithlove.com/2011/01/advanced-drawing-using-appkit.html

dizzywhip
Dec 23, 2005

Carthag posted:

Cocoa With Love had a post that might be helpful, it includes positioning a glyph:

http://cocoawithlove.com/2011/01/advanced-drawing-using-appkit.html

I actually stumbled upon this post a couple days ago while researching a different problem but I skipped over the character part :downs:. I won't be able to try this until later, but this looks like it'll work for sure since you're drawing the path yourself.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Gordon Cole posted:

It's totally opaque. I don't know if it matters for this particular situation, but I should mention that I'm using a non-layer backed view. I know layer-backed views have weird issues with doing sub-pixel text rendering, but those shouldn't apply here.

Hmm, I'm out of ideas then. Sorry!

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Changed my question since I figured out qthe one I posted earlier

I've added unit tests to a bundle project and get the following error:

quote:

2012-01-12 01:23:33.644 otest[12650:407] The test bundle at /.../DerivedData/.../Debug/PluginTests.octest could not be loaded because a link error occurred. It is likely that dyld cannot locate a framework framework or library that the the test bundle was linked against, possibly because the framework or library had an incorrect install path at link time.
2012-01-12 01:23:33.649 otest[12659:203] *** NSTask: Task create for path '/.../DerivedData/.../Debug/PluginTests.octest/Contents/MacOS/PluginTests' failed: 22, "Invalid argument". Terminating temporary process.

Things I've checked:
- bundle is added to Bundle Loader in Test Target's Build Setting: $(BUILT_PRODUCTS_DIR)/Plugin.agplugin/Contents/MacOS/Plugin
- bundle build is a Target Dependency in Build Phases.
- bundle build is also in the scheme (both build & test phases).

Carthag Tuek fucked around with this message at 01:36 on Jan 12, 2012

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Has anyone taken a class at Big Nerd Ranch?

Another guy and I at work are tasked with getting up to speed on iPhone stuff, I have some experience but he's starting from scratch (but has done plenty of web programming). The boss would prefer to just send us somewhere for a week, they've used Pragmatic Programmer classes before.

I'm wondering if they just re-hash what's in the books.

wolffenstein
Aug 2, 2002
 
Pork Pro
A friend of mine did the Big Nerd Ranch course for Cocoa Programming. While it is re-hashing the book (which you get to keep a copy of), they do it at an accelerated pace, you meet and talk to other Cocoa programmers, and they cover everything but airfare. He thought it was well worth it.

dizzywhip
Dec 23, 2005

Carthag posted:

Cocoa With Love had a post that might be helpful, it includes positioning a glyph:

http://cocoawithlove.com/2011/01/advanced-drawing-using-appkit.html

Success! It's a lot of code but it works perfectly. Thanks a bunch.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Carthag posted:

I've added unit tests to a bundle project and get the following error:


Things I've checked:
- bundle is added to Bundle Loader in Test Target's Build Setting: $(BUILT_PRODUCTS_DIR)/Plugin.agplugin/Contents/MacOS/Plugin
- bundle build is a Target Dependency in Build Phases.
- bundle build is also in the scheme (both build & test phases).

Gah, I've tried just about everything now! Every setting I find online is either already set correctly, or it doesn't fix the problem.

I've compared the build settings & schemes to a working test target in another project, and run otool -L on everything I could think of. There's nothing at all I can find that is linked to in a way that doesn't make sense!

Also what's up with not saying what exactly the linking error is... :(

Carthag Tuek fucked around with this message at 09:19 on Jan 12, 2012

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Maybe not the most helpful suggestion but: try GHUnit?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



I guess I'll have to try that out tomorrow. I still haven't found out what the problem is. Does GHUnit integrate with XCode (ie do test failures go in the isssue navigator / get shown in the code window)?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



I decided to have one last go at it before ditching OCUnit and it works now, although it seems like a hack. For future reference, I removed the bundle from the BUNDLE_LOADER var in build settings, and added all .m files to the Tests target.

I guess it has something to do with the way .app classes vs. .bundle classes are loaded into the testing harness, cause .app classes don't need to be in the Test target.

--

I'm building a queue (basically an NSMutableOrderedSet that gets items added to it during the course of the program). I want to periodically check this queue and handle the first object in it (and remove it). I suppose this is a good job for GCD? Or should I use an NSTimer for this?

Edit: Ah, Timer dispatch sources

Carthag Tuek fucked around with this message at 19:11 on Jan 13, 2012

Morphix
May 21, 2003

by Reene
The OP says I can ask about getting a dev to design an application.

I need something simple that I can run on my Iphone 4s that keeps track of a simple weight based inventory and allows me to mark sales that remove stock from the inventory automatically.

I can photoshop up a few screens but the UI could be default buttons or text for all I care, as long as it's easy to read.

Here is sort of a breakdown of what I need it to do via the interface

Title Screen:

Inventory
Sale

Inventory
-Add Crop
---- Add Specific Food Item (name, 140 character description, weight, desired price per lb)
-View Inventory sorted by Crop

Sale
- Add a sale of a specific food item by weight, so an input box with gram/oz/lb buttons next to it
- It suggests a price based off the desired x/lb price, but allows me to input whatever price
- Auto updates the inventory

Anyway, fairly simple but apparently spreadsheets don't work that great on iOs and it's not like I'd know how to design the automated sale bit anyway.

What would I be looking at to have something like this made? I've checked the various inventory, POS software stuff and all of it's too complicated for what I'm trying to do nor do most of them allow you to have items by weight. Quick Sale is sorta there but I hate that it syncs to a website and I'd be forced to price everything by the gram which is a hassle including too many maths.

Morphix fucked around with this message at 00:13 on Jan 14, 2012

Small White Dragon
Nov 23, 2007

No relation.
Is there a good way to "debug" what your application has on iCloud?

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Morphix posted:

Stuff.

Well since you didn't request response by PM I assume responding publicly will be OK and it might help others with similar questions.

The short answer is "it depends". If you just want a one-off for your own use, then I imagine a CS student or part-timer could knock it out for a few hundred bucks (give or take) and depending on exactly how complex it is.

If you want a polished app and someone to help you get the app through the approval process to sell on the store, has experiece doing more professional development like localizing/translating, dealing with users and bug/crash reports, etc then you are looking at more money. By way of example and assuming I had time on my schedule, my price would probably start at 2000 and go up from there. If you want an integrated bug tracker, a graphic artist, translations, a website for the app, etc then that obviously adds to the cost.

You will definitely get better responses and more accurate prices if you have mockups for the screens you want. Also make sure if you are spending more than a few bucks that you deal with someone who has their own app out on the app store and make sure you check that it really is their app and any references they can provide. Unfortunately there are a lot of crappy coders out there taking people's money and churning out absolute garbage in between parking cars at their "real" job. I know because I've had to clean up (re-write from scratch) their mistakes. Good developers are also in high demand so if someone has a completely free schedule that might be a red flag.

I don't want to sound down on part-time devs, beginners, or students... Everyone has to start somewhere, just make sure you aren't paying top dollar and have the correct expectations up front. Having an eager student do a one-off app can be a great deal for you both. Having the same person write the app your 10,000 customers will use in the US, France, and China to interact with your company is a less appealing idea.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Small White Dragon posted:

Is there a good way to "debug" what your application has on iCloud?

I don't know if there is an official way but I often write little apps that I run on the simulator or on my test devices to do tasks like this.... Eg: in the simulator you can access the real file system, so I have an app that can rip directories to a known location for inspection. I have another that has various UI layouts and writes both 1X and 2X screenshots for startup image purposes. I'm sure you could have a test app with the right bundle IDs and just have it dump everything it can see from iCloud to a local folder.

Morphix
May 21, 2003

by Reene

Ender.uNF posted:

Well since you didn't request response by PM I assume responding publicly will be OK and it might help others with similar questions.

The short answer is "it depends". If you just want a one-off for your own use, then I imagine a CS student or part-timer could knock it out for a few hundred bucks (give or take) and depending on exactly how complex it is.


Thank you for the response, sorry I don't have PM on this account I guess. I'm looking for something one-off, not for store resale in anyway, in fact I was going to have another developer look through the code to make sure there is nothing that uploads any data to anywhere.

I'll work on some props and repost here with some more info. What I'm looking for a good Excel spreadsheet could do, but alas can't get excel poo poo to run on an iphone and doing it via safari on google docs doesn't seem to give me much functionality.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Some developers weighing in on the pricing of big prestige apps: http://stackoverflow.com/questions/209170/how-much-does-it-cost-to-develop-an-iphone-application

Khelmar
Oct 12, 2003

Things fix me.
OK, I've got a Core Data question. I'm working my way through the Stanford lectures, which are really, really helpful, but for my app, I'd like to have a table view that displays information sorted by date. The sorting I get, but is there a simple way with NSPredicate to ask for "all records with a unique month and year" to make creating sections in the table view easy, or do I have to do this myself?

Basically, if the data is:

11/10/05 1 1 1
11/15/05 2 1 0
12/02/05 4 2 0
03/10/06 1 0 1
04/21/06 0 0 0

is there a way to get a set of 11/05, 12/05, 03/06, and 04/06 without going through every possible month and year with an NSPredicate of "between these dates" and checking to see how many records match?

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



Khelmar posted:

OK, I've got a Core Data question. I'm working my way through the Stanford lectures, which are really, really helpful, but for my app, I'd like to have a table view that displays information sorted by date. The sorting I get, but is there a simple way with NSPredicate to ask for "all records with a unique month and year" to make creating sections in the table view easy, or do I have to do this myself?

Basically, if the data is:

11/10/05 1 1 1
11/15/05 2 1 0
12/02/05 4 2 0
03/10/06 1 0 1
04/21/06 0 0 0

is there a way to get a set of 11/05, 12/05, 03/06, and 04/06 without going through every possible month and year with an NSPredicate of "between these dates" and checking to see how many records match?

Something like this I presume from looking at the docs a bit:

  • Fetch & sort the objects you want to display
  • Set up an NSMutableArray for storage and an NSMutableIndexSet to keep group header indexes.
  • Check the first of your objects, save year+month, and insert an object that will become the section header
  • Enumerate the objects:
    • Check if year/month is higher than "current" - if they are update the "current" vals, insert a new header with the new values, and save the current index.
    • Now insert the object into the array.

Now you have an array where each section is separated by their group headers + the indexes of the headers. Use this new array as the dataSource for the table view.

Then in your delegate:
- (BOOL)tableView:(NSTableView *)tableView isGroupRow:(NSInteger)row
{
return [headerIndex containsIndex:row];
}

That should tell the tableview whether the object is a group header or not, and have it draw it accordingly. Note I haven't tried this yet, but will probably be building my own somewhere down the line.

Carthag Tuek fucked around with this message at 05:09 on Jan 19, 2012

OHIO
Aug 15, 2005

touchin' algebra
Do any of you use TestFlight? Their crash reporting feature looks awesome, except it doesn't support AppStore releases.

Is there a way to keep receiving crash reports? Or do you transition to something else?

Doctor w-rw-rw-
Jun 24, 2008

Sulk posted:

AddressBar.h:

code:
#import <Foundation/Foundation.h>

@interface AddressBar : UITextField <UITextInputTraits> {
    @private
    // I'm unsure if anything should go here
}

blah blah blah

I use this general pattern. It isolates the retain/release semantics in the property definition. Thanks to the Objective-C 2.0 runtime, even explicit ivars aren't a huge advantage over synthesized ivars (more info). Perhaps the method synthesis might not be such a big performance win, but I haven't noticed any performance issues since I don't need close-to-the-metal performance at the class level. In any case, you can directly access the synthesized ivars if you somepropertyname = _ivarname in your synthesis statement.

SomeClass.h:
code:
#import <Foundation/Foundation.h>
// "Core imports" - i.e. stuff that needs to be here for the header to make any sense

@interface SomeClass : SomeSuperclass <ImplementedProtocolOne, ImplementedProtocolTwo, ImplementedProtocolEtc>

@property(nonatomic, retain) SomeObject someObject;
@property(nonatomic, assign) NSInteger somePrimitiveType;
@property(nonatomic, assign) id<SomeDelegateProtocol> someDelegateImplementingSomeDelegateProtocol;
@property(nonatomic, copy) NSString someImmutableType;
@property(nonatomic, retain, readonly) SomeExposedObject someExposedObject;

@end
SomeClass.m:

code:
#import "SomeClass.h"
// "Implementation imports" - i.e. stuff that isn't important to the interface of the class

// This is the empty category, or in other words it defines methods that the
// compiler will complain about if they're not implemented. It doesn't do
// that with named categories, which merely define methods that may be
// added to the class.
@interface SomeClass() 

- (void)aPrivateMethod;

@property(nonatomic, retain, readwrite) SomeExposedObject someExposedObject;
@property(nonatomic, retain) SomeInternalVariable someInternalVariable;

@end


@implementation SomeClass

@synthesize someObject, somePrimitiveType, someDelegate, someImmutableType, someExposedObject;
@synthesize someExposedObject, someInternalVariable;

- (void)aPrivateMethod {

}

- (void)dealloc {
  self.someObject = nil;
  self.somePrimitiveType = nil;
  self.someDelegate = nil;
  self.someImmutableType = nil;
  self.someExposedObject = nil;

  self.someExposedObject = nil;
  self.someInternalVariable = nil;
  [super dealloc];
}
@end
Do note, however, that private methods need only to be called by name from the outside*; the runtime itself doesn't have a notion of public/private. If you class-dump the Cocoa touch framework, you can see all kinds of nifty functions that aren't public. C functions, however, are much trickier to find.

* This means, for example, if you know of a private property in some third-party class, you can implement a category on it that declares methods *it already has*, and then include that header with the category on your code, and use those methods with no warnings from the compiler.


OHIO posted:

Do any of you use TestFlight? Their crash reporting feature looks awesome, except it doesn't support AppStore releases.

Is there a way to keep receiving crash reports? Or do you transition to something else?
You might be interested in QuincyKit. I have not yet used it myself, but it looks interesting and possibly useful. Maybe it's what you're looking for?

Doctor w-rw-rw- fucked around with this message at 20:38 on Jan 19, 2012

Adbot
ADBOT LOVES YOU

sleepness
Feb 9, 2006

Hey friendly programmer goons. I'm looking for a developer looking for some extra cash to help me with a project I want to implement. It's very simple, so I don't think you need to be a professional to do this.

I'm looking for a pretty simple application. I will send all the necessary fonts and logos and text needed. What I need the app to do is have 4 buttons on the home page, that once clicked, displays some text that I will provide on a different page, as well as a "Find My Race!" button (will describe this later.) I also need a "Go back home" button that takes you to the home screen. Also, on the home page, I will need a facebook and twitter button.

As for the find my race button, I don't know how easy or hard this would be for a developer, but this is what I'm picturing in my head. They press the button. Either the GPS goes off and locates them, or they can input their zip (Whichever is easier). Then, after that, the application will find the nearest event to that person based on where they are located.

If that part is too difficult, I can deal with just the other features working nicely. Shoot me an e-mail at rjkaszuba at gmail if you are interested. I will pay a fair amount, don't want to cheap anyone out!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply