/r/ObjectiveC

Photograph via snooOG

Your news for everything ObjectiveC related.

/r/ObjectiveC

6,987 Subscribers

10

alloc method and insufficient memory

In C malloc can fail if there is not enough memory in the system. What happens if I try [NSObject alloc] while there is no memory available? Does it abort? Return NULL?

8 Comments
2022/08/25
17:21 UTC

4

I need someone experienced in iOS to help with a devious bug

9 Comments
2022/08/02
20:21 UTC

3

Do I use ObjectiveC for making stuff on MacOS

So I have been wanting to make things like custom dock bar and things like that for my mac for quite a while. So I wanted to know if I would use ObjectiveC for that? or am I supposed to use another language, also how long would it take me to learn ObjectiveC to a degree at which I could accomplish what I mentioned above

23 Comments
2022/07/28
20:37 UTC

7

Is there a difference between [self attributeName] and self.attributeName ?

Hello,

I'm an objective-C newbie, and I've got to work on some legacy code. A question I can't find a clear answer to is the difference between `[self attributeName]` and `self.name.`

So I declare a .h for a class, its attributes and methods and I want to interact with them in the .m. I usually feel more comfortable using `self.name` for assigning a value to the class's attribute and `[self attributeName]` for reading the value of the attribute, but I feel like they're totally interchangeable.

Am I correct or is there a real difference I'm missing ?

Thanks in advance !

7 Comments
2022/06/29
21:03 UTC

3

Block capture in a nested blocks

-(void) someFunction {
    ApiClass *apiObj = [[ApiClass alloc] init];
    SomeObj *obj = [SomeObj objWithName:@"First Last"]; // Autoreleased obj
    [apiObject doThingWithBlock:^(){   // Block - 1 (async - runs after 5 mins)
        // Do some work
        // ...
    
        apiObject doAnotherThingWithBlock:^(){    // Block - 2
            [obj performTask];
        };
    }];
    [apiObject release];
}

If Block - 1 runs asynchronously, when is obj captured in Block - 2? If its not captured when the literal is seen, wouldnt it result in obj being released before the Block - 2 can retain it when it is executed 5 mins later??

1 Comment
2022/05/05
01:00 UTC

6

[PyObj-C] Can't see any notifications when calling postNotification: method from NSNotificationCenter

This is what PyObj-C is,

"a bridge between the Python and Objective-C programming languages on macOS."

I am trying with Foundation to post a notification. I have had a successful NSNotification call of notificationWithName:object: below, and I (believe I) instantiate it with defaultCenter().postNotificationName:object:userInfo.

@objc.IBAction
def helplink_(self, url):
    print("ensssss")
    x = Cocoa.NSNotification.notificationWithName_object_("hi", 88)
....Cocoa.NSNotificationCenter.defaultCenter().postNotificationName_object_userInfo_("name", x, None)
    print(x)

However, I sadly dont get any notifications, is there another way I should be doing this (on Catalina) with other instance or type/instance methods? I'm not sure what to do besides do trial and error with other class objects to get the right comonbation.

ANY Help would be GREATLY appricated. Thanks! (On macOS 10.15.7)

BTW, whats the sender and receiver exactly in this Framework? Good resource for what it is?

16 Comments
2022/03/15
18:48 UTC

4

How to get the row index from the sender ID object of a button within a cell in the row of an NSTableView? (macOS, no swift UI involved)

I have a NSTableView that dynamically adds rows when the user enters relevant data. The table has a few columns and the last column contains a button that removes the row if needed. As it stands now, The row has to be selected to get its index. If the row isn't selected the button does nothing. So I would like to know if there is a way I can get the index of the row without having the select the row. So basically when the button is pressed is there a way I can obtain the index of row it's from without the row itself being selected. I'm new to objective C and I've been having quite lot of trouble figuring this out.

3 Comments
2021/12/20
05:43 UTC

4

What changes would you make to the open source code of an abandoned browser (Stainless) to make it compatible with Mojave, or Big Sur and Monterey?

https://lowendmac.com/2014/stainless-browser-light-and-efficient-but/

What I find valuable is the “Single Session” functionality. With it, you can log into two different accounts of your favorite social media site (Facebook, Twitter, etc.). It will store the login credentials in RAM as opposed to a cookie, so when you close that tab the stored information is erased. For example, you have two Twitter accounts – one personal and one professional. Start up a Single Session, and you can have both running in separate tabs. Close the tab, and all that login information is erased.

Stainless was a browser that seems to be no longer functioning on the modern macOS (and not maintained by the creator). I liked the fact that if you had multiple accounts for one website, you could bookmark that, and it would not only bookmark the website but also keep you signed in, so that if you click that bookmark, it would go to the site with you already logged in.

This way you could make multiple bookmarks of the same website with different IDs.

If you have multiple Reddit IDs for example, it would be easy to switch from one account to another without having to log out.

How would you make another browser like this?

The developer wrote this about Stainless:

Stainless started out as a technology demo to showcase my own multi-processing architecture in response to Google Chrome (Stainless 0.1 was released three weeks after Google released Chrome for Windows). Sensing an opportunity and inspired by a growing fanbase, I decided to craft Stainless into a full-fledged browser and work on features that I hadn't seen before in other browsers.

A prime example is parallel sessions, which allow you to log into a site using different credentials in separate tabs at the same time. This new technology is woven throughout Stainless, from the private cookie storage system, to session-aware bookmarks that remember the session in which they were saved. I still believe this is a true browser innovation, and I'd love to see this implemented in Chrome.

Over the past couple of years it's been impossible for me to keep working on Stainless and as promised to many, here it is, finally available as open source and in need of serious maintenance. My last update (on 7/25/2011) was almost two years after I had stopped active development (11/04/09), and it was pretty much a bugfix release. As I had expected, Stainless remained interesting to users until Google finally released Chrome Beta for the Mac in September of 2009.

If you are going to fork, the easy path would be to setup a development system on Snow Leopard running XCode 3. That way you could build the current source successfully as it requires method swizzling (for multi-session cookie storage in WebKit) and private access to CoreGraphics internals (for handling cross-process window layering). The hard path would be to replace these with modern equivalents under XCode 4 (caveat: you would lose the PowerPC compatibility, which has helped keep Stainless popular on machines that can't run Chrome).

In the end, Stainless is still a hack: multi-process by way of carefully layered multi-applications with a shared state. And as a hack, some of its most serious issues (running in separate spaces for example) may be insurmountable. Still, Stainless was a hack to which I devoted over a year of my life and learned a lot about tricking OS X into doing my bidding. Hopefully it can still provide similar inspiration for other Mac developers. https://github.com/mesadynamics/stainless

3 Comments
2021/11/19
10:36 UTC

5

How to open up URL which is part of NSString?

Hi, I've got a string for exmaple like this - "sadsadsad https://www.youtube.com/results?search_query=martin+garrix"

How can I open up that url which is a part of NSString?

10 Comments
2021/09/02
07:15 UTC

0

How to modify MacOS dock and things like that

Hi, I would like to know how I could modify things such as the Dock and Finder with objective c.

14 Comments
2021/08/31
07:24 UTC

12

Hi. It's the Objective-C noob again.

I just finished going through the Programming with Objective-C guide and also the Start Developing Mac Apps Today guide but I have not had much chance to get to code anything yet (aside from some basic experiments with syntax and all that). I'm also quite new to coding (< 1 year experience) and I'm wondering where I could find some hands-on exercise to practice the concepts I've learned and also familiarize myself with Xcode. Thank you in advance!

9 Comments
2021/08/08
05:35 UTC

4

function (const __strong NSString *const paths[], int count)

I am looking at an open source github project and I stumbled upon this declaration. Can someone explain why all these qualifiers were needed.

22 Comments
2021/07/31
14:44 UTC

12

Objective C Resources in 2021

I'm looking to contribute to my company's Objective-C code base, but I have no experience in iOS development. Any recommendations concerning resources to get up to speed quickly? Is it mostly learning syntax, language idioms, and frameworks?

4 Comments
2021/07/23
16:22 UTC

2

What could cause a crash in NSRecursiveLock?

I have a crash where the top of the stack looks like

0   libobjc.A.dylib        0x000000019ba5a5b4 object_getIndexedIvars + 36
1   com.apple.Foundation   0x000000019ca0bff4 -[NSRecursiveLock lock] + 20
2   com.apple.Foundation   0x000000019ca0bff4 -[NSRecursiveLock lock] + 20

I'm pretty sure that allocation initialized the lock.

What should I try?

9 Comments
2021/07/19
22:38 UTC

8

Great Danish company Looking for mac developers from anywhere (Codebase Objective C but gradually going for Swift)

The company is called CaptureOne, focused around the software with the same name, which is the best raw conversion program in the world, with increasing amount of image editing tools similar to those of photoshop.

I am a windows developer working there myself, and can tell you that it is an awesome place to work! Ask me anything.The main reason I chose to search myself, is because I am seeing an increasing distance between windows and mac developer capacity with so many eager windows developers. I want the company to continue thriving and develop as fast as possible, but the windows cannot do that if the mac cannot, as we want to keep the two platforms aligned.

While it is prefered to have developers in the offices in Denmark/Greece, they recently started hiring cross country as well, and maybe even help you move if you want. See https://careers.captureone.com/ad/mac-software-engineer/r8nhi1 for Mac developer and try to apply if interested.https://careers.captureone.com/work-with-us for other open positions

Best regards, ols.

Let me know if you successfully got a position, that'd be awesome

8 Comments
2021/07/06
12:08 UTC

6

Hi! Please help me with this complex block

Hi! I have (sort of) a complex block here that apparently takes a block as argument and returns another block and I'm having a hard time telling where the return type is (I might be wrong about the parameters too so please correct me). I'm guessing it's the entire thing that starts from (^ (^complex... but I expected the syntax to look like this. Please enlighten me! Tysm for your time!

Combined screenshots: https://imgur.com/a/3yKnyfi

1 Comment
2021/07/05
07:35 UTC

6

Objective c on windows

Hi I want to learn objective c on windows and i found that i could do this by installing mingw on my pc and using Gnucore but i want to know how to connect all of them with IDE that helps me like Xcode on mac os i want an IDE for developing on windows

12 Comments
2021/07/02
21:29 UTC

2

Looking for Freelance Mobile App Devs

Hey Everybody,

I currently have a client that needs a couple of developers who can use Objective C and possibly have experience in building Android apps as well.

For some background, my company is called Autolance. We are a freelance matching service that instantly matches pre-vetted freelancers with projects that perfectly match their skillsets.

If you are interested, feel free to comment here, DM me privately, or go straight to this link (https://www.autolance.co/freelancers) and book a meeting slot so we can hop on a call.

I will also answer any questions you guys have on here directly.

Thanks!

2 Comments
2021/07/02
20:45 UTC

2

Help Request: UITableView AutoLayout / Layout constraints

Hi

Can anyone help me with layout of a uitableview on rotation?

  1. When my view loads, the UITableView lays out as requested in a subview, whether that load starts in portrait or landscape.
  2. When I rotate the simulator, the UITableview appears in the new relative position but retains its initial width, and does not update. See the enclosed screenshots.
  3. Im using arrays of layout constraints to instruct the new positions of all the subviews on rotation and Ive checked them - all and all seem fine (see the attached images). The other coloured views all rotate and layout correctly which seems to me to evidence that rotation and layout are working.
  4. The instructions Ive provided for the UITableview load include the following frame and layout instructions. A couple of other points - Ive found that if I don't provide a frame with dimensions the UITableview doesn't appear (ie if I provide CGRect frame = CGRectMake(0,0,0,0); Also, providing autoresizingFlexibleHeight adjusts the height but I can’t find any similar property for width:

CGRect frame = CGRectMake(kTableViewLeftInset, kTableViewTopInset, holder.frame.size.width - kTableViewLeftInset - kTableViewRightInset, holder.frame.size.height - kTableViewTopInset - kTableViewBottomInset);

_dataTableView = [[UITableView alloc]initWithFrame:frame style:UITableViewStylePlain];

_dataTableView.translatesAutoresizingMaskIntoConstraints = false;

_dataTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;

(The kTableView constant values Im using are : kTableViewTopInset is 67,kTableViewBottomInset = 20;kTableViewLeftInset = 20;kTableViewRightInset = 20; just in case you're wondering about the height from the top)

Im fairly sure Im missing something (probably fundamental :) ) so any steer would be very welcome.

Thanks in advance

Loads in Portrait = OK, Happy........

rotates to landscape...tableview width not updating, Not Ok, Sad.

2 Comments
2021/07/01
18:42 UTC

6

How exactly do header files work?

Header files include interfaces intended for public use, while implementation files include the code for whatever declared in the interface. However, if I were to send the .h file to someone without the .m, how would they be able to use it? I don't understand how the header file would be able to work without the implementation file that contains the code to be executed. :P

5 Comments
2021/06/30
03:22 UTC

3

From Objective-C to Swift and the latest innovations at Apple

0 Comments
2021/06/29
12:19 UTC

2

Hi please help me with the question below. How do I add a category to a class and calling through another (already existing) category of that class?

Add a category to NSString in order to add a method to draw the uppercase version of a string at a given point, calling through to one of the existing NSStringDrawing category methods to perform the actual drawing. These methods are documented in NSString UIKit Additions Reference for iOS and NSString Application Kit Additions Reference for OS X.

4 Comments
2021/06/17
04:37 UTC

4

Hi it's the Obj-C newbie again. I'm wondering if I should put all of the methods to be implemented in the .h file? I'm asking cause I put a custom accessor method in the .m file without declaring it in the .h and didn't get any error or warning. Thanks!

7 Comments
2021/06/16
02:57 UTC

2

Hi it's me again. I have a question regarding inheritance of classes.

In this example (I'm following Apple's Objective-C guide), XYZShouthingPerson is a subclass of XYZPerson. I tried declaring secondPerson as type XYZPerson (XYZPerson *secondPerson) and the program still works. Is there any particular reason why I should declare secondPerson as type XYZPerson instead of XYZShoutingPerson? (The guide told me to declare secondPerson as type XYZPerson and I'm not sure why).

5 Comments
2021/05/26
05:19 UTC

Back To Top