Swift Core Data NSPredicate static string issueCore Data Predicate not workingCore Data, NSPredicate and to-many keyNSPredicate - Unable to parse the format stringHow to escape a trailing backslash in an NSPredicate format stringCore Data NSPredicate with a fetch property as criteria?Get Entities that fulfill predicate even some have null object for parentCore Data - Swift - Catch “keypath not found in entity” errorNSPredicate 'IN' operator formatting issue in swift. Unable to parse the format stringCore data use aggregate function in filterSwift Core Data Predicate IN ClauseNSPredicate to filter Core Data Relationship NSSet by attribute

Many many thanks

Can someone identify this unusual plane at airport?

Why does the `ls` command sort files like this?

Did anybody find out it was Anakin who blew up the command center?

Is there any problem with a full installation on a USB drive?

No hyphenation on "section", "Table", etc. with Cleveref package

Time difference between banns and marriage

Why does this London Underground poster from 1924 have a Star of David atop a Christmas tree?

Units in general relativity

Is a memoized pure function itself considered pure?

Group riding etiquette

Is the internet in Madagascar faster than in UK?

Fantasy Macro Economics: What would Merfolk Trade?

How to pass 2>/dev/null as a variable?

Why does a sticker slowly peel off, but if it is pulled quickly it tears?

How to force GCC to assume that a floating-point expression is non-negative?

Book featuring a child learning from a crowdsourced AI book

How do we improve collaboration with problematic tester team?

Why this brute force attack doesn't reduce all cryptographic hash functions' security bits against collision attacks to N/3?

Can an object tethered to a spaceship be pulled out of event horizon?

How could a self contained organic body propel itself in space

Defending Castle from Zombies

Can I take a boxed bicycle on a German train?

Federal Pacific 200a main panel problem with oversized 100a 2pole breaker



Swift Core Data NSPredicate static string issue


Core Data Predicate not workingCore Data, NSPredicate and to-many keyNSPredicate - Unable to parse the format stringHow to escape a trailing backslash in an NSPredicate format stringCore Data NSPredicate with a fetch property as criteria?Get Entities that fulfill predicate even some have null object for parentCore Data - Swift - Catch “keypath not found in entity” errorNSPredicate 'IN' operator formatting issue in swift. Unable to parse the format stringCore data use aggregate function in filterSwift Core Data Predicate IN ClauseNSPredicate to filter Core Data Relationship NSSet by attribute






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I would like to make predicate more flexible for changes. I have lot of such strings in the sources code:



let predicate = NSPredicate(format: "bodyPart.name = %@", name)

let filteredExercises = ExerciseEntity.mr_findAll(with: predicate)


but as you see if I will change BodyPart name to MuscleGroup for example someday it will cause issue like:



Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath bodyPart.name not found in entity <NSSQLEntity ExerciseEntity id=5>'


I am searching for the solution with a key paths like



let predicate = NSPredicate(format: "%@ = %@", BodyPart.name, name)









share|improve this question
























  • Compare stackoverflow.com/a/41638253/1187415.

    – Martin R
    Mar 27 at 20:55

















0















I would like to make predicate more flexible for changes. I have lot of such strings in the sources code:



let predicate = NSPredicate(format: "bodyPart.name = %@", name)

let filteredExercises = ExerciseEntity.mr_findAll(with: predicate)


but as you see if I will change BodyPart name to MuscleGroup for example someday it will cause issue like:



Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath bodyPart.name not found in entity <NSSQLEntity ExerciseEntity id=5>'


I am searching for the solution with a key paths like



let predicate = NSPredicate(format: "%@ = %@", BodyPart.name, name)









share|improve this question
























  • Compare stackoverflow.com/a/41638253/1187415.

    – Martin R
    Mar 27 at 20:55













0












0








0








I would like to make predicate more flexible for changes. I have lot of such strings in the sources code:



let predicate = NSPredicate(format: "bodyPart.name = %@", name)

let filteredExercises = ExerciseEntity.mr_findAll(with: predicate)


but as you see if I will change BodyPart name to MuscleGroup for example someday it will cause issue like:



Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath bodyPart.name not found in entity <NSSQLEntity ExerciseEntity id=5>'


I am searching for the solution with a key paths like



let predicate = NSPredicate(format: "%@ = %@", BodyPart.name, name)









share|improve this question














I would like to make predicate more flexible for changes. I have lot of such strings in the sources code:



let predicate = NSPredicate(format: "bodyPart.name = %@", name)

let filteredExercises = ExerciseEntity.mr_findAll(with: predicate)


but as you see if I will change BodyPart name to MuscleGroup for example someday it will cause issue like:



Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath bodyPart.name not found in entity <NSSQLEntity ExerciseEntity id=5>'


I am searching for the solution with a key paths like



let predicate = NSPredicate(format: "%@ = %@", BodyPart.name, name)






ios swift core-data nspredicate






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 20:38









Matrosov AlexanderMatrosov Alexander

9,34939 gold badges120 silver badges234 bronze badges




9,34939 gold badges120 silver badges234 bronze badges















  • Compare stackoverflow.com/a/41638253/1187415.

    – Martin R
    Mar 27 at 20:55

















  • Compare stackoverflow.com/a/41638253/1187415.

    – Martin R
    Mar 27 at 20:55
















Compare stackoverflow.com/a/41638253/1187415.

– Martin R
Mar 27 at 20:55





Compare stackoverflow.com/a/41638253/1187415.

– Martin R
Mar 27 at 20:55












1 Answer
1






active

oldest

votes


















2















Use %K to substitute the key path



let predicate = NSPredicate(format: "%K = %@", #keyPath(BodyPart.name), name)





share|improve this answer



























  • It should be #keyPath(BodyPart.name), compare stackoverflow.com/a/41638253/1187415

    – Martin R
    Mar 27 at 20:53











  • Thanks for the reminder about #keyPath

    – Joakim Danielson
    Mar 27 at 20:55











  • thanks for comments

    – Matrosov Alexander
    Mar 27 at 21:18











  • it will just return "name == some name" but I need "bodyPart.name", for sure I can combine to strings I guess) thanks good solution!

    – Matrosov Alexander
    Mar 27 at 21:20







  • 1





    @MatrosovAlexander, shouldn't it be like Martin R suggests above #keyPath(ExerciseEntity.muscle.name)?

    – Joakim Danielson
    Mar 27 at 21:28










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386045%2fswift-core-data-nspredicate-static-string-issue%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2















Use %K to substitute the key path



let predicate = NSPredicate(format: "%K = %@", #keyPath(BodyPart.name), name)





share|improve this answer



























  • It should be #keyPath(BodyPart.name), compare stackoverflow.com/a/41638253/1187415

    – Martin R
    Mar 27 at 20:53











  • Thanks for the reminder about #keyPath

    – Joakim Danielson
    Mar 27 at 20:55











  • thanks for comments

    – Matrosov Alexander
    Mar 27 at 21:18











  • it will just return "name == some name" but I need "bodyPart.name", for sure I can combine to strings I guess) thanks good solution!

    – Matrosov Alexander
    Mar 27 at 21:20







  • 1





    @MatrosovAlexander, shouldn't it be like Martin R suggests above #keyPath(ExerciseEntity.muscle.name)?

    – Joakim Danielson
    Mar 27 at 21:28















2















Use %K to substitute the key path



let predicate = NSPredicate(format: "%K = %@", #keyPath(BodyPart.name), name)





share|improve this answer



























  • It should be #keyPath(BodyPart.name), compare stackoverflow.com/a/41638253/1187415

    – Martin R
    Mar 27 at 20:53











  • Thanks for the reminder about #keyPath

    – Joakim Danielson
    Mar 27 at 20:55











  • thanks for comments

    – Matrosov Alexander
    Mar 27 at 21:18











  • it will just return "name == some name" but I need "bodyPart.name", for sure I can combine to strings I guess) thanks good solution!

    – Matrosov Alexander
    Mar 27 at 21:20







  • 1





    @MatrosovAlexander, shouldn't it be like Martin R suggests above #keyPath(ExerciseEntity.muscle.name)?

    – Joakim Danielson
    Mar 27 at 21:28













2














2










2









Use %K to substitute the key path



let predicate = NSPredicate(format: "%K = %@", #keyPath(BodyPart.name), name)





share|improve this answer















Use %K to substitute the key path



let predicate = NSPredicate(format: "%K = %@", #keyPath(BodyPart.name), name)






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 27 at 20:55

























answered Mar 27 at 20:45









Joakim DanielsonJoakim Danielson

14.7k3 gold badges8 silver badges27 bronze badges




14.7k3 gold badges8 silver badges27 bronze badges















  • It should be #keyPath(BodyPart.name), compare stackoverflow.com/a/41638253/1187415

    – Martin R
    Mar 27 at 20:53











  • Thanks for the reminder about #keyPath

    – Joakim Danielson
    Mar 27 at 20:55











  • thanks for comments

    – Matrosov Alexander
    Mar 27 at 21:18











  • it will just return "name == some name" but I need "bodyPart.name", for sure I can combine to strings I guess) thanks good solution!

    – Matrosov Alexander
    Mar 27 at 21:20







  • 1





    @MatrosovAlexander, shouldn't it be like Martin R suggests above #keyPath(ExerciseEntity.muscle.name)?

    – Joakim Danielson
    Mar 27 at 21:28

















  • It should be #keyPath(BodyPart.name), compare stackoverflow.com/a/41638253/1187415

    – Martin R
    Mar 27 at 20:53











  • Thanks for the reminder about #keyPath

    – Joakim Danielson
    Mar 27 at 20:55











  • thanks for comments

    – Matrosov Alexander
    Mar 27 at 21:18











  • it will just return "name == some name" but I need "bodyPart.name", for sure I can combine to strings I guess) thanks good solution!

    – Matrosov Alexander
    Mar 27 at 21:20







  • 1





    @MatrosovAlexander, shouldn't it be like Martin R suggests above #keyPath(ExerciseEntity.muscle.name)?

    – Joakim Danielson
    Mar 27 at 21:28
















It should be #keyPath(BodyPart.name), compare stackoverflow.com/a/41638253/1187415

– Martin R
Mar 27 at 20:53





It should be #keyPath(BodyPart.name), compare stackoverflow.com/a/41638253/1187415

– Martin R
Mar 27 at 20:53













Thanks for the reminder about #keyPath

– Joakim Danielson
Mar 27 at 20:55





Thanks for the reminder about #keyPath

– Joakim Danielson
Mar 27 at 20:55













thanks for comments

– Matrosov Alexander
Mar 27 at 21:18





thanks for comments

– Matrosov Alexander
Mar 27 at 21:18













it will just return "name == some name" but I need "bodyPart.name", for sure I can combine to strings I guess) thanks good solution!

– Matrosov Alexander
Mar 27 at 21:20






it will just return "name == some name" but I need "bodyPart.name", for sure I can combine to strings I guess) thanks good solution!

– Matrosov Alexander
Mar 27 at 21:20





1




1





@MatrosovAlexander, shouldn't it be like Martin R suggests above #keyPath(ExerciseEntity.muscle.name)?

– Joakim Danielson
Mar 27 at 21:28





@MatrosovAlexander, shouldn't it be like Martin R suggests above #keyPath(ExerciseEntity.muscle.name)?

– Joakim Danielson
Mar 27 at 21:28








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386045%2fswift-core-data-nspredicate-static-string-issue%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript