Igor Delovski Board Forum Index Igor Delovski Board
My Own Personal Slashdot!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Objective C

 
Post new topic   Reply to topic    Igor Delovski Board Forum Index -> Mac Cocoa
Mac Cocoa  
Author Message
XNote
Kapetan


Joined: 16 Jun 2006
Posts: 532

PostPosted: Thu Sep 18, 2008 7:11 pm    Post subject: Objective C Reply with quote

forums.macrumors.com - Function pointers in Obj-C

"Hi, so how do you pass function pointers via class/instance methods in obj-c?"
Back to top
View user's profile Send private message
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Mon Sep 22, 2008 11:22 pm    Post subject: Reply with quote

SO - How can I dynamically create a selector at runtime?

"I know how to create a SEL at compile time using @selector(MyMethodName:)
but what I want to do is create a selector dynamically from an NSString. Is this
even possible?"
Back to top
View user's profile Send private message Visit poster's website
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Thu Oct 02, 2008 11:26 am    Post subject: Reply with quote

SO - What are best practices that you use when writing Objective-C and Cocoa?

"I know about the HIG (which is quite handy!), but what programming practices
do you use when writing Objective-C, and more specifically when using Cocoa (or
CocoaTouch)."
Back to top
View user's profile Send private message
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Tue Oct 07, 2008 7:29 pm    Post subject: Reply with quote

SO - What is the best way to solve an Objective-C namepsace collision?

"E.g. if you have a conflict because some C library has a function named open(),
you could define a variable named myOpen and have it point to the open()
function of the library, thus when you want to use the system open(), you
just use open() and when you want to use the other one, you access it via
the myOpen identifier."


See also: Choose Your Own Prefix at CocoaDev.
Back to top
View user's profile Send private message Visit poster's website
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Thu Oct 09, 2008 4:40 pm    Post subject: Reply with quote

iphonedevsdk.com - Apple coding conventions question

"This is the correct way.
Code:
UIView *localVariable = [[UIView alloc] initWithFram....];
self.instanceVariable = localVariable;
[localVariable release];

I'm guessing that instanceVariable has been defined as (nonatomic, retain)?
Because "self." is used before instanceVariable it means that localVariable will
be passed through the setter method. All the setter method does is release the
old value and retain the current one."
...


Code:
- (void) myInstanceMethod
{
   instanceVariable = [[UIView alloc] initWithFram....];
}
"Yes that is fine.

You could as an alternative do the following:"

Code:
self.instanceVariable = [[[UIView alloc] initWithFram....]autorelease];
Back to top
View user's profile Send private message
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Fri Oct 17, 2008 11:43 pm    Post subject: Reply with quote

SO - Cocoa Bad Habits

"What are those bad habits you've developed since you've started coding in
Cocoa?"
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Sun Oct 19, 2008 2:45 am    Post subject: Reply with quote

SO - Hidden features of Objective-C

"Objective-C as a language is getting wider use due to its use by Apple for
Mac OS X and iPhone development. What are some of your favourite 'hidden'
features of the Objective-C language?"
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Sun Dec 14, 2008 1:07 am    Post subject: Reply with quote

MF - How to make global variables in ObjectiveC

"By encapsulating your variables in a Singleton for development, you can
then easily make it read such a file to load the values at a later point in time
and, if you are writing to them, helps you separate them out functionally."
Back to top
View user's profile Send private message Visit poster's website
XNote
Kapetan


Joined: 16 Jun 2006
Posts: 532

PostPosted: Fri Mar 27, 2009 7:00 pm    Post subject: Reply with quote

mikeash.com - Friday Q&A 2009-03-20: Objective-C Messaging

"How does messaging work, and what exactly does it do? Read on!"
Back to top
View user's profile Send private message
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Sat Apr 11, 2009 3:22 pm    Post subject: Reply with quote

adc - Dynamic Method Resolution

"An Objective-C method is simply a C function that take at least two argum-
ents—self and _cmd. You can add a function to a class as a method using the
function class_addMethod."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Sun Jun 14, 2009 10:24 pm    Post subject: Reply with quote

mobileorchard.com - id<Protocol>, Retain/Release and Protocol Inheritance

"Enter protocol inheritance. You can declare a protocol to inherit from another
protocol as follows:"

Code:
@protocol Inherits<Base>
- (void)foo;
@end
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Sat Jul 04, 2009 2:56 am    Post subject: Reply with quote

reddit - Android versus iPhone Development: A Comparison

"Firstly, it has to be stringByAppending, because appendString: is used by NS-
MutableString to actually modify the receiver itself, rather than creating a new
string.

Secondly, there are other stringByAppending*: methods, like stringByAppend-
ingFormat:, stringByAppendingPathExtension:, and stringByAppendingPathCo-
mponent:. "
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Wed Aug 12, 2009 11:34 pm    Post subject: Reply with quote

so - Inheritance Issues in Objective C

"The short, easy answer: Don't make a subclass of NSArray. It's better to
make a category on NSArray or make an NSObject subclass that has an
NSArray ivar that you talk to."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Sun Aug 23, 2009 8:42 pm    Post subject: Reply with quote

phrack.org - The Objective-C Runtime: Understanding and Abusing

"The topic of this research is the Objective-C runtime on Mac OS X. Basically,
during the contents of this paper, i will look at how the Objective-C runtime
works both in a binary, and in memory. I will then look at how we can mani-
pulate the runtime to our advantage, from a reverse engineering / exploit de-
velopment and binary infection perspective."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Wed Aug 26, 2009 10:58 pm    Post subject: Reply with quote

macdevelopertips.com - Objective-C Object as a C Structure

"Okay, so figuring out how to unwind an Objective-C object into its base re-
presentation goes against all that is object-oriented programming, however,
it’s interesting none-the-less."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Sun Sep 06, 2009 3:48 pm    Post subject: Reply with quote

Slashdot: How Snow Leopard Cut ObjC Launch Time In Half

"Greg Parker has an excellent technical article on his blog about the cha-
nges to the dynamic linker (dyld) for Objective-C that Snow Leopard uses
to cut launch time in half and cut about 1/2 MB of memory per application.

'In theory, a shared library could be different every time your program is
run. In practice, you get the same version of the shared libraries almost
every time you run, and so does every other process on the system. The
system takes advantage of this by building the dyld shared cache. The sha-
red cache contains a copy of many system libraries, with most of dyld's
linking and loading work done in advance. Every process can then share
that shared cache, saving memory and launch time.' He also has a post
on the new thread-local garbage collection that Snow Leopard uses for Ob-
jective-C."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Sun May 09, 2010 5:01 pm    Post subject: Reply with quote

Mac Developer Tips - Objective-C: Private Methods

"One common complaint for many new to Objective-C is that the language
lacks support for private methods within a class.

To implement hidden methods you can use categories."

@interface SomeClass (hidden)
...
@implementation SomeClass (hidden)


"An alternative way to declare a private class method is described in the
Objective-C 2.0 documentation. If you are writing your own class, you can
add private methods that are implemented directly within the main imple-
mentation block of the class by declaring an empty category."

@interface MyObject ()
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Thu Jun 03, 2010 6:30 pm    Post subject: Reply with quote

Slashdot - Objective-C Enters Top Ten In Language Popularity

"Objective-C has entered the top 10 of the Tiobe Programming Community
Index. Last year, it was at #39. The huge jump is attributed to its use in
iPhone and iPad development. C, of which Objective-C is a strict superset,
has reclaimed the #1 spot from Java, which slides to #2."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Wed Sep 08, 2010 12:17 pm    Post subject: Reply with quote

MF - Which Singleton class is better?

"Unit testers hate, with a passion, singletons. They hate singletons because
they screw up unit testing royally. They will give you all kinds of reasons why
singletons are bad but the bottom line is that singletons screw up unit testing.
Royally."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Tue Aug 02, 2011 12:17 pm    Post subject: Reply with quote

Mike Nachbaur - Back to basics: Key Value Observing

"Key-Value-Observing, or more commonly KVO, is a mechanism by which
you can observe changes to keys and their values bound to an object. It
lets you make arbitrary objects aware of changes made to values in other
objects that are important to you."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Tue Nov 08, 2011 1:22 pm    Post subject: Reply with quote

Ray Wenderlich - Beginning ARC in iOS 5 Tutorial Part 1

"The most disruptive change in iOS 5 is the addition of Automatic Reference
Counting, or ARC for short. ARC is a feature of the new LLVM 3.0 compiler
and it completely does away with the manual memory management that all
iOS developers love to hate."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Sun Jun 03, 2012 3:04 pm    Post subject: Reply with quote

so - Add method selector into a dictionary

"The combination of NSStringFromSelector and NSSelectorFromString as
answered above is probably the best way to go. But if you really want to,
you can use a selector as a value or key in an NSDictionary. ... but a po-
inter can be wrapped in an NSValue object that can be used."


Code:
dictionary = [NSDictionary dictionaryWithObject:[NSValue valueWithPointer:selector] forKey:key];
Back to top
View user's profile Send private message Visit poster's website
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Wed Oct 03, 2012 3:39 pm    Post subject: Reply with quote

mikeash.com - Friday Q&A 2010-01-22: Toll Free Bridging Internals

"Toll-free bridging, or TFB for short, is a mechanism which allows certain
Objective-C classes to be interchangeable with certain CoreFoundation
classes."
Back to top
View user's profile Send private message
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Thu Aug 22, 2013 8:11 pm    Post subject: Reply with quote

Nils Hayat - From C Declarators to Objective-C Blocks Syntax

"In this post, I start with the simplest C declarator and build in complexity
until we get to Objective-C blocks syntax. It took me a while to get block
syntax but once you understand how it is organized and where it comes
from, there is no looking in Google every time you need to declare a block
anymore."
Back to top
View user's profile Send private message Visit poster's website
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Sat Nov 09, 2013 1:35 am    Post subject: Reply with quote

objc.io - A periodical about best practices and advanced techniques in Objective-C

"objc.io was founded in Berlin by Chris Eidhof, Daniel Eggert, and Florian
Kugler. We started objc.io to create a regular platform for in-depth tech-
nical topics relevant to all iOS and OS X developers."
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Thu Sep 11, 2014 8:13 pm    Post subject: Reply with quote

codementor.io - Introduction to Objective-C Literals for iOS Beginners

"Objective-C literals are a more simple, shorthand method for working with
some common Objective-C constructs. These include the following:

NSNumber
NSArray
NSDictionary"


Code:
NSDictionary *dictionaryLiteral = @{@"key1": firstLiteral, @"key2": secondLiteral};


Code:
NSNumber *firstLiteral = @7;
NSNumber *secondLiteral = @10;
NSNumber *sumLiteral = @([firstNumber intValue] + [secondNumber intValue]);


Code:
 NSArray *arrayLiteral = @[firstLiteral, secondLiteral];


Last edited by Ike on Sun Jan 22, 2023 9:43 pm; edited 1 time in total
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Tue Oct 07, 2014 3:15 pm    Post subject: Reply with quote

aceontech.com - @weakify(self): A more elegant solution to weakSelf in Objective-C

"The obvious solution to this problem is to define a weak reference to self
before the block (let's call it weakSelf), and use that instead while calling
into self from a block."
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Fri Jul 14, 2017 12:57 pm    Post subject: Reply with quote

nshipster - NS_ENUM & NS_OPTIONS

"Introduced in Foundation with iOS 6 / OS X Mountain Lion, the NS_ENUM and
NS_OPTIONS macros are the new, preferred way to declare enum types."
Back to top
View user's profile Send private message
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Mon Jan 15, 2018 10:45 pm    Post subject: Reply with quote

Developer Aapple Blog - Nullability and Objective-C

"At the core of this feature we have two new type annotations: _Nullable and
_Nonnull. As you might expect, a _Nullable pointer may have a NULL or nil
value, while a _Nonnull one should not. The compiler will tell you if you try to
break the rules.

You can use _Nullable and _Nonnull almost anywhere you can use the nor-
mal C const keyword, though of course they have to apply to a pointer type.

However, in the common case there's a much nicer way to write these an-
notations: within method declarations you can use the non-underscored
forms nullable and nonnull immediately after an open parenthesis, as long
as the type is a simple object or block pointer."
Back to top
View user's profile Send private message Visit poster's website
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Wed Feb 07, 2018 12:42 pm    Post subject: Reply with quote

https://blog.instabug.com/2018/02/ios-11-developer-features/

iOS 11 is arguably one of the biggest operating system releases in Apple history. Not only did it come packed with tons of updates, but it also included a bunch of new features, as well as APIs, frameworks, and integrations that can help developers build better and more intelligent apps.
Back to top
View user's profile Send private message
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Sat Mar 17, 2018 11:51 pm    Post subject: Reply with quote

Paul Hudson - Why many developers still prefer Objective-C to Swift

"But if you're still using Objective-C, you're not alone - many other developers
still prefer Objective-C to Swift, and with good reasons. I got in touch with
some Objective-C developers to ask what's holding them back, whether they
feel Objective-C development has become stigmatized, and more - here's what
they had to say..."
Back to top
View user's profile Send private message Visit poster's website
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Sun Jul 22, 2018 4:13 pm    Post subject: Reply with quote

so - Return value for performSelector:

"An example of using NSInvocation to return a float:"

Code:
SEL selector = NSSelectorFromString(@"someSelector");
if ([someInstance respondsToSelector:selector]) {
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:
                                [[someInstance class] instanceMethodSignatureForSelector:selector]];
    [invocation setSelector:selector];
    [invocation setTarget:someInstance];
    [invocation invoke];
    float returnValue;
    [invocation getReturnValue:&returnValue];
    NSLog(@"Returned %f", returnValue);
}
Back to top
View user's profile Send private message
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Tue Aug 28, 2018 4:33 pm    Post subject: Reply with quote

Hamster Emporium archive - TargetConditionals.h

TARGET_OS_OSX, TARGET_OS_IOS, TARGET_OS_TV, TARGET_OS_WATCH,
TARGET_OS_SIMULATOR, TARGET_OS_MAC, TARGET_OS_IPHONE,
TARGET_OS_EMBEDDED...


so - Preprocessor macro for OS X targets?
Back to top
View user's profile Send private message Visit poster's website
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Thu Nov 01, 2018 4:52 pm    Post subject: Reply with quote

https://www.onlineinterviewquestions.com/objective-c-interview-questions/

Objective C Interview Questions
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Sat Feb 23, 2019 10:18 pm    Post subject: Reply with quote

so - NS_ASSUME_NONNULL_BEGIN Macro

"It's a convenience macro to save you typing nonnull in your headers. From
the Swift blog detailing how new safety features have been incorporated back
in Objective-C."


Code:
- (AAPLListItem * _Nullable)itemWithName:(NSString * _Nonnull)name;
- (nullable AAPLListItem *)itemWithName:(nonnull NSString *)name;

@property (copy, nullable) NSString *name;
@property (copy, readonly, nonnull) NSArray *allItems;


Last edited by Ike on Sat Feb 18, 2023 8:52 pm; edited 1 time in total
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Sat Feb 23, 2019 10:18 pm    Post subject: Reply with quote

so - NS_ASSUME_NONNULL_BEGIN Macro

"It's a convenience macro to save you typing nonnull in your headers. From
the Swift blog detailing how new safety features have been incorporated back
in Objective-C."


See Nullability and Objective-C - https://developer.apple.com/swift/blog/?id=25

useyourloaf.com - Using nullable to annotate Objective-C code

"Most of the time we tend to want nonnull references. We can make that
the default for a region of code by using NS_ASSUME_NONNULL_BEGIN
and NS_ASSUME_NONNULL_END.

We then only need to add nullable annotations for references that can be nil.
Our annotated class now looks like this:"


Code:
NS_ASSUME_NONNULL_BEGIN
@interface Robot : NSObject
@property (copy,readonly) NSString *name;
- (nullable instancetype)initWithName:(NSString *)name;
- (nullable NSString *)tellMeSomething;
@end
NS_ASSUME_NONNULL_END


Last edited by Ike on Sat Feb 18, 2023 9:11 pm; edited 2 times in total
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Mon Apr 08, 2019 11:09 pm    Post subject: Reply with quote

so - Difference between typeof, __typeof and __typeof__ (Objective-c)

"Clang does support the use of typeof(), but technically it's for when your C
Language Dialect is set to be a gnu* type. However __typeof__() is supported
in both c* and gnu* language dialects - as detailed in the Clang
documentation.

Now if you're writing your code with Xcode, the default setting for the C
language dialect appears to be GNU99 and the option of allowing 'asm' 'inline'
'typeof' is set to Yes, so using typeof() won't bring you any problems."
Back to top
View user's profile Send private message
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Sat Jun 27, 2020 3:57 pm    Post subject: Reply with quote

wwdc - Advancements in the Objective-C runtime

"Dive into the microscopic world of low-level bits and bytes that underlie every
Objective-C and Swift class. Find out how recent changes to internal data
structures, method lists, and tagged pointers provide better performance and
lower memory usage. We'll demonstrate how to recognize and fix crashes in
code that depend on internal details, and show you how to keep your code
unaffected by changes to the runtime."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Wed Jul 15, 2020 9:45 am    Post subject: Reply with quote

Swiftjective-C - A Best in Class iOS App

"Voice Over is fully supported and the rotor control is implemented by including the relevant headings. Using Screen Curtain yields an experience that's not only usable, but up to par with the regular app using only Voice Over.

Voice Over gestures are overridden where necessary:

Escape: A two-finger Z-shaped gesture that dismisses a modal dialog, or goes back one level in a navigation hierarchy.
func accessibilityPerformEscape() -> Bool

Magic Tap: A two-finger double-tap that performs the most-intended action.
func accessibilityPerformMagicTap() -> Bool

Three-Finger Scroll: A three-finger swipe that scrolls content vertically or horizontally.
func accessibilityScroll(_ direction: UIAccessibilityScrollDirection) -> Bool

Increment: A one-finger swipe up that increments a value in an element.
func accessibilityIncrement()

Decrement: A one-finger swipe down that decrements a value in an element.
func accessibilityDecrement()

Voice Control is also supported, and appropriate accessibilityUserInputLabels are set if needed.
Your app respects the following settings:
Including Bold Text.
High Contrast Cursors."
Back to top
View user's profile Send private message Visit poster's website
delovski



Joined: 14 Jun 2006
Posts: 3522
Location: Zagreb

PostPosted: Tue Oct 06, 2020 8:52 pm    Post subject: Reply with quote

r - Write CGI scripts in Objective-C with objcgic

"If you want to write small web applications as CGI scripts in Objective-C,
consider this little library. Tested primitively on GNUstep on GNU/Linux."
Back to top
View user's profile Send private message Visit poster's website
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Tue Dec 08, 2020 12:37 pm    Post subject: Reply with quote

__bridge vs __bridge_transfer vs __bridge_retained

"__bridge
OBJECTIVE-C ← → CF ... no transfer of ownership;

__bridge_transfer
CF → OBJECTIVE-C
Moves a Core Foundation pointer to Objective-C with transfer of the ownership to ARC

__bridge_retained
OBJECTIVE-C → CF
Moves an Objective-C pointer to Core Foundation and transfers ownership and also responsibility of releasing the memory to you"
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Sun Jul 25, 2021 10:25 am    Post subject: Reply with quote

git - class-dump

"class-dump is a command-line utility for examining the Objective-C segment
of Mach-O files. It generates declarations for the classes, categories and
protocols"
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Sat Jul 31, 2021 11:10 pm    Post subject: Reply with quote

so - Find where object is retained with ARC

"This solution was somewhat helpful for me. It basically uses method
swizzling to tricks the ARC compiler into thinking you're not overriding
retain and release."


Code:
Method originalMethod1 = class_getInstanceMethod(cls, originalSelector1);
Method swizzledMethod1 = class_getInstanceMethod(cls, swizzledSelector1);


BOOL didAddMethod1 =
    class_addMethod(cls,
                    originalSelector1,
                    method_getImplementation(swizzledMethod1),
                    method_getTypeEncoding(swizzledMethod1));
...
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Tue Oct 26, 2021 9:28 pm    Post subject: Reply with quote

clang.llvm.org - Objective-C Automatic Reference Counting (ARC)

"The primary purpose of this document is to serve as a complete technical
specification of Automatic Reference Counting. Given a core Objective-C
compiler and runtime, it should be possible to write a compiler and runtime
which implements these new semantics."
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Sun May 22, 2022 9:46 pm    Post subject: Reply with quote

YT - Objective C Programming - Learn Objective C Programming

"Learn Objective C programming. This 8-part course provides a full introduction
into all the basic fundamentals and core concepts of Objective C programming
for beginners. Learn how to code - learn ObjC programming the easy way."
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Sun Jan 22, 2023 1:01 am    Post subject: Reply with quote

so - Fixing ARC error when using Objective-C object in struct

"The safest way is to use __unsafe_unretained or directly CFTypeRef and
then use the __bridge, __bridge_retained and __bridge_transfer."

Code:
typedef struct Foo {
    CFTypeRef p;
} Foo;

int my_allocating_func(Foo *f)
{
    f->p = (__bridge_retained CFTypeRef)[[MyObjC alloc] init];
    ...
}

int my_destructor_func(Foo *f)
{
    MyObjC *o = (__bridge_transfer MyObjC *)f->p;
    ...
    o = nil; // Implicitly freed
    ...
}


"This response is outdated. As of WWDC '18, you are now allowed to specify ARC object pointers in C structs. - Daniel J

It appears that at least __strong and __weak are now supported in structs
by clang (2019). - Carl Lindberg"
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Mon Jan 23, 2023 5:23 pm    Post subject: Reply with quote

How to wrap a Struct into NSObject

Code:
// Then sort of "wrap" it to an NSValue object like:

aStruct struct; struct.a = 0; struct.b = 0;
NSValue *anObj = [NSValue value:&struct withObjCType:@encode(aStruct)];
NSArray *array = @[anObj];

// To pull the struct out from NSValue use:

NSValue *anObj = [array firstObject];
aStruct struct;
[anObj getValue:&struct];
Back to top
View user's profile Send private message
Ike
Kapetan


Joined: 17 Jun 2006
Posts: 3025
Location: Europe

PostPosted: Wed Sep 06, 2023 6:27 pm    Post subject: Reply with quote

mjtsai.com - Topic: Objective-C

"Posts Tagged Objective-C"

- Objective-C Internals (1)August 10, 2023
- Objective-C Messages to nil (4)February 22, 2022
- Optionals in Swift Objective-C Interoperability (1)February 3, 2022
- Constant Literals in Objective-C June 9, 2021
- Be Careful With Obj-C Bridging in Swift (4)March 2, 2021
- Resources for Learning Objective-C and AppKit (4)April 13, 2020
- Objective-C Quiz (6)February 6, 2020
- Optionals in Swift Objective-C Interoperability (5)January 16, 2020
- ...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Igor Delovski Board Forum Index -> Mac Cocoa All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Delovski.hr
Powered by php-B.B. © 2001, 2005 php-B.B. Group